What is it called when one of these methods gets applied to a Functor's value?
See original GitHub issueThe simplest example I can think of is here:
https://github.com/folktale/data.either/blob/master/lib/either.js#L252-L259
An Either doesn’t exactly have a concat, but if its an Either of a Semigroup, then you can concat the underlying Semigroup simply by calling concat. Is there a specific term for these kind of operations on the values of functors? They’re basically just a layer of indirection on top of map or chain.
I’m building a parser combinators library and I’m not sure if its Kosher to allow a concat method to join parser results together.
concat(p) {
return this.chain(vs => p.map(v => vs.concat([v])))
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
C++ Tutorial: Functors (Function Objects) - 2020
In other words, a functor is any object that can be used with () in the manner of a function. This includes normal...
Read more >Functors in C++ - GeeksforGeeks
A functor (or function object) is a C++ class that acts like a function. Functors are called using the same old function call...
Read more >What are these applicative functors you speak of? | Devlog
This method is usually called map , its only purpose is to give us access to the value so we can transform it...
Read more >What is a functor? - Medium
A post in Functional JavaScript Blog states that a functor is a function that, “given a value and a function, unwraps the values...
Read more >What are C++ functors and their uses? - Stack Overflow
A functor is a class or struct object which can be "called" like a function. This is made possible by overloading the ()...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ccorcos I don’t have an answer to your title question. The examples you give can lead to some discussion though.
Either a b
has more than one implementation forSemigroup
. For instance:That implementation does not rely at all on the underlying value. I know you mentioned
Either a b
as an example, but it’s important to remember that we can sometimes do things differently.Your parser combinator library could function in a similar way. Instead of trying to
concat
the underlying value,concat
the structure. This is what naturally falls out of parser combinators anyway in a language with support for higher kinded polymorphism. TheAlt
,Plus
, andAlternative
algebras follow naturally from parser combinators. The reason we havealt
asf a ~> f a -> f a
instead ofa ~> a -> a
is precisely because we want to talk aboutconcat
ing the structure and not the underlying value.The point I’m trying to make is that you should explore using
Alt
,Plus
, andAlternative
for your parser combinator library.I find it pretty useful.
I can make a safe
find
that tells me what happened without trying too hard. It’s safe in the sense that I don’t have to deal withnull
orundefined
.That’s too restrictive and not really something the spec should care about. It’s way too low level of a thing to add. In the scope of
Semigroup
, we shouldn’t care if anEither a b
data type even exists. We should definitely not special case the spec for data types. That leads to the craziness of promises.It also severely limits the usefulness of
Semigroup
. You’d expect that something like this could be written once and for all:But saying that
Either a b
cannot do such a thing would make this function really awkward.data.either does that in this case: https://github.com/folktale/data.either/blob/f9b20a582c7287528df328a5d13a662b8d454b52/lib/either.js#L244. Well, it requires a
Monoid
, but close enough.Please contribute with some examples! You’re writing a perfect one for
Alt
,Plus
andAlternative
. There’s more discussion here: https://github.com/fantasyland/fantasy-land/issues/177.