question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Move to prefixed Fantasy Land methods

See original GitHub issue

As 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:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
boris-marinovcommented, Sep 8, 2016

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.

1reaction
robotlolitacommented, Sep 24, 2016

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) requires x to be the same type as someValidation. 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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Namespaced prefixes — next step for resolving name clashes ...
The next step is to eventually publish a version of fantasy-land npm package with namespaced prefixed names. There are some questions to discuss...
Read more >
What's more fantastic than fantasy land? An Introduction to ...
Fantasy land is great. It opens up a whole world of interoperable functions and structures. And the title, though originally a joke, ...
Read more >
fantasyland/fantasy-land - Gitter
@kasselTrankos make simple test first, the associative law state (a + b) + c = a + (b + c) where + is...
Read more >
Choose Your Multi-Player Methods: Solo or Team Style, Ultima or ...
So making Ultima a multi-player online world was a natural. You choose a male or female avatar (graphic representation of yourself), and choose...
Read more >
prefix Phone field, different Objects - Salesforce Stack Exchange
You could further add a describe method that finds phone fields ... for(sObject record: sObjectsList) { switch on (record) { when Account ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found