Fantasy Land 1.0
github.com
github.com
https://github.com/Avaq/Fluture is basically lazy and better promises. A+ spec got nothing on this.
https://github.com/sanctuary-js/sanctuary adds better typechecks, combinators, and types like Maybe.
https://github.com/origamitower/folktale An upcoming collection of similar tools for JavaScript.
And of course, there's Ramda.
I think these libraries may sound impossible to use at work at first, but if you play with them for fun, you can at least learn some cool techniques or paradigms.
Better how? Does it for example support unbounded recursion without stack overflow?
function f(n) {
if (n > 0) return Promise.resolve(n - 1).then(f)
}
Because promises do (there is no maximum n above)Also at a quick glance I see the following:
> Be careful when cancelling a hooked Future. If the resource was acquired but not yet consumed, it will no longer be disposed
This works in Bluebird; the resource will be disposed even if the promise is cancelled.
Being Lazy has the advantages of laziness which is that if you do not clean your room, you became a hoarder and your room overflows.
The point I am making is that either of these tools are not holy grail. I do not think a solution for all is going to exist, just use them when it best suits the application - I think ( Like its just my dumb opinion )
also @spion I think we are going to take this argument to our death beds :D
... but, all these libraries are huge. I feel guilty foisting hundreds of kilobytes of JS on my users, just so I can write code that I feel is slightly more elegant. I'm avidly waiting for tree-shaking/jsnext:main to truly take hold, and make these tools more practical.
Gripes aside, congratulations to the Fantasy Land team :).
Combine it with a decent transpiler (I recommend Bublé) and Uglify and you're off to the races: tiny builds, that work wonderfully.
If you set up a concat+minifying step in your process (you should be doing this anyways if you're shipping a real amount of JS) then the total cost of a library like this might just be a couple kilobytes.
Angular.JS (which has a huge amount of functionality in its core) is only 50kb gzipped.
Yes, I have a concat/minifying step, but as I mentioned, I'd love to see broader acceptance/implementation of tree-shaking. As it is, tying together fantasy-land, Ramda/mori, React, Redux all adds up very quickly (and that's without writing any business logic!).
The trick to not breaking your build is to know which libraries GCC can optimize without breaking.
The ones it can - browserify them seperately and then ones it cannot - browserify them later.
Its a longer step I agree, but its a small price to pay to be in Fantasy Land :D
( sorry couldn't help it )
Or are you more worried about page load time, not download time?
typically unless you're like me and clear cache when the browser closes...
Linking to shared libraries hosted on a CDN often ends up failing because of distinct versions.
Every object conforms to an interface, including some error handling functions. The interface is about composition and transformation and iteration/operation (map).
Is this about functional programming? It seems like it must, but I know very little about that and still have no real idea what the benefit of this is or even its purpose.
Edit: So I see that these are algebraic properties that are being defined, to relate it to my limited knowledge I see that Setoid define an equivalence relation interface, equals, which your objects must conform to.
My next question is what is the benefit of programming like this? Maybe I'd have to brush up on my algebra and learn how these relationships/"specifications" are useful.
I am actually kinda curious about this, but it's a little hard to penetrate.
around ch9 ( https://drboolean.gitbooks.io/mostly-adequate-guide/content/... ) they start mentioning fantasy-land and you should also have a good background in what FL is trying to achieve.
Another benefit is that these abstractions appear again and again under many contexts. Recognizing them allows you to give them a common interface, instead of flatMap for lists, andThen for promises, and so on.
> the last API you'll ever need
So like... if I wanted to make a post to twitter, I'm pretty sure I'd need another API.
The chart on the fantasy-land github page demonstrates the interfaces available on each typeclass. For instance, a Maybe is a functor, so it has the map interface. It's also a Monad so it has the chain interface.
Unfortunately, API is a loaded term and I think the author doesn't do a good job differentiating from the common usage of the term.
Even then, I need to know what the names of the properties are that I have to provide to the fantasy-land-compliant-whatever. Being an expert in fantasy land doesn't tell me that "message" is the property that contains the body of the twitter-compliant message. I still need an api.
I think the confusion here arises from a fairly common conflation of a web service with the interface used to interact with said service.
value["functionName"](...[arguments])
value is the the thing you're operating on. functionName is the name of the thing you want to do. arguments are any other relevant values.> (aka "Algebraic JavaScript Specification")
It's a JS library to implement algebras in code. And:
> An algebra is a set of values, a set of operators that it is closed under and some laws it must obey.
> Each Fantasy Land algebra is a separate specification. An algebra may have dependencies on other algebras which must be implemented.
So that is it. It's "weird", it has a lot of functional concepts (which may or may not be present already in the language -- I'm not a JS-guy myself). It sure must be interesting working on code that does all the things this project does, and I can see it must've required it's share of effort.
https://youtube.com/watch?list=PLMs_JcuNozJa7tg80N_kITisZjHH...
There's something wrong with me.