Finally, the core Promises/A+ specification does not deal with how to create, fulfill, or reject promises, choosing instead to focus on providing an interoperable then method. Future work in companion specifications may touch on these subjects.
As a functional developer, I usually deal with monads and operators like point
bind
map
or flatMap
to chain calls that are wrapped inside some monad box.
According to this question Js Deferred/Promise/Future compared to functional languages like Scala, the map
and flatMap
operators seems to be melted together under then
in the js spec, probably because it would not make so much sense to provide both in a dynamically typed language like Js (?) and it is more convenient to use and remember a single operator.
So far so good, there's a then
operator (that doesn't seem to always be properly implemented)
But why do the promise create / fulfill / reject is not part of the spec? It's like just having an half a monad :( It seems I'm not the only one to complain
Typically, my problem is:
- I want to create a JS library
- I want to expose a promise-based API
- I want the client to choose the promise implementation he wants to use
Now what am I supposed to do?
I can create promises in my library like
Q.fcall(function () {
return 10;
})
Ok cool, I just coupled my library to Q :(
So, is there any solution to this problem? How a library author is supposed to create the promises he exposes to the API without coupling to the implementation?
Is there some license-free minimum viable promise A+ library that we can embed in our libraries or something?
What are the reasons behind this spec choice?