On 29 January 2014 10:45, Paolo Amadini <paolo.02....@amadzone.org> wrote:
> On 29/01/2014 5.12, Kris Kowal wrote: > > In this case, a half pursuit of type purity is a side quest at the > > expense of users. Having two ways to resolve and two ways to observe a > > promise is unnecessarily confusing. In my experience, one method like > > "then", that unwraps recursively, and one function, like "Promise.cast", > > that automatically lifts if necessary, and "then" handlers that return > > into the waiting hands of "Promise.cast" are coherent and ergonomic. > > Having a choice between "cast" and "resolve" and a choice between "then" > > and "chain", will leave developers unnecessarily confused and worried > > all the while they use or abandon Promises as too subtle. > > As an imperative programmer, I confirm I'm left worried and confused ;-) > > But I understand that functional programming might need more complexity. > It is, actually, more simplicity. The concept of `Promise.resolve` and `Promise.chain` is simpler than `Promise.cast` and `Promise.then` (i.e.: they represent orthogonal concepts, not "complected"). `Promise.cast` and `Promise.then` may be, arguably, *easier* to work with, from a user POV, since you don't need to make as many choices. I would argue that it would make more sense to write `cast` and `then` in terms of `resolve` and `chain`, however. But this seems to have already been decided. Answering your previous question: ```js var p1 = Promise.resolve(Promise.cast(1)); var p2 = Promise.cast(Promise.cast(1)); ``` `p1` will be a `Promise(Promise(1))`, whereas `p2` will be `Promise(1)` — IOW, `Promise.resolve` will just put anything inside of a `Promise`, regardless of that being a promise or a regular value, whereas `Promise.cast` will put the innermost value that is not a promise inside of a promise. ```js var p3 = new Promise(resolve => resolve(Promise.cast(1)); // is the same as: var p3 = Promise.resolve(Promise.cast(1)) ``` -- -- Quildreen "(Soreλ\a)" Motta (http://robotlolita.github.io/<http://killdream.github.com/> ) *— JavaScript Alchemist / Minimalist Designer / PLT hobbyist —*
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss