Killing `Promise.fulfill`

Mark S. Miller erights at google.com
Mon Aug 19 20:41:20 PDT 2013


How does what you mean by .then here differ from .flatMap? If it is the
same, why not rename your .then to .flatMap and rename your .when to .then ?


On Mon, Aug 19, 2013 at 8:14 PM, Kevin Smith <zenparsing at gmail.com> wrote:

> Implementation:
>
>     function unwrap(value) {
>         return Promise.resolve(value).then(v => isPromise(v) ? unwrap(v) :
> v);
>     }
>
>     Promise.when = value => unwrap(value);
>
> Test:
>
>     var promise = new Promise(r => {
>         r.fulfill(new Promise(r => { r.fulfill(1); }));
>     });
>
>     promise.then(val => console.log(val.then ? "promise" : "value"));
>     Promise.when(promise).then(val => console.log(val.then ? "promise" :
> "value"));
>
>     >> promise
>     >> value
>
> { Kevin }
>
>


-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130819/3d6b2bc9/attachment-0001.html>


More information about the es-discuss mailing list