Move to prefixed Fantasy Land methods
See original GitHub issueAs of 0.3 the Fantasy-Land specification now uses prefixed names (i.e.: type['fantasy-land/map'](fn)
rather than type.map(fn)
). Folktale 2 should support this accordingly.
Because we’re still supporting the same set of features older versions of Folktale do, so people can transition their codebase without as many problems, we’ll be using compatibility methods to let people call these namespaced functions. That is, each type will look like this:
Type.prototype['fantasy-land/map'] = function(fn) {
return Type(fn(this.value));
};
Type.prototype.map = function(fn) {
return this['fantasy-land/map'](fn);
}
We should also encourage people to use the Core.FantasyLand module instead of calling the methods directly when they’re writing generic functions (e.g.: a function that works with any functor, rather than just Folktale’s Maybe). This direction is documented here: https://github.com/origamitower/folktale/blob/master/ROADMAP.hs#L106-L297
Types that need fixing
- Maybe
- Either
- Validation
- Task
- Future
See https://github.com/fantasyland/fantasy-land/pull/146 for details on the Fantasy-Land decision.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
I am all for supporting Fantasy Land, but are we sure we want to remove the old names?
They will still be useful for playing in the REPL, or for code examples (even the Fantasy Land Spec uses them in that context).
Plus, I imagine that not all folktale users care about Fantasy Land (some probably just want a safer alternative of promises, for instance) and for them the prefix will be just an annoyance.
I’ve been thinking about this in the past weeks (work’s been eating all my time lately :x), and yeah, there isn’t really any reason we couldn’t have the methods.
It also just struck me that all functions in Fantasy Land use consistent types anyway, so
someValidation.ap(x)
requiresx
to be the same type assomeValidation
. So, wherever users are writing non-generic functions (e.g.: a function that works with a Maybe, rather than a Functor), it’s always safe to invoke the short method (maybe.map(f)
is guaranteed to always work).The problem only happens when users are writing generic functions (e.g.: a function that works with any Functor), in those cases,
functor.map(f)
is not safe, because different libraries might have defined the methods in different places.It would be nice if we could warn people of this, but we can’t really detect the cases where it matters, so I suppose our best option is (rather than outputting warnings) describing this in the documentation, and recommending people to use the Core.FantasyLand module’s functions when writing generic operations.
Thanks @boris-marinov and @safareli for the input 😃