briancavalier / avow

Example Promises/A+ implementation. Simple, tiny, fast, fully async
Other
31 stars 5 forks source link

Implement `Promise.of` #2

Closed Raynos closed 11 years ago

Raynos commented 11 years ago

As per https://github.com/promises-aplus/resolvers-spec/issues/24 and https://github.com/pufuwozu/fantasy-land#constructorof-method

Should be pretty simple and then you'll have compliance

briancavalier commented 11 years ago

I'll do this in a branch for exploration. Can fantasy-land provide some code to help here? For example, a simple program that performs some abstract operations over the monad interface, where I can just plug an avow promise in and see it work?

briancavalier commented 11 years ago

Closed by e9e3725

Raynos commented 11 years ago

Does this work for a promise containing a promise ? or will that get flattened out?

briancavalier commented 11 years ago

Yeah, of(x) uses x verbatim as the fulfillment value. For example:

avow.of(avow.of(123)).then(function(p) { console.log(typeof p.then === 'function'); });
briancavalier commented 11 years ago

However, I didn't change the flattening behavior of then().

Raynos commented 11 years ago

That's ok. x.then(function (xValue) { return Promise.of(xValue) }) should correctly be "equivelant" to x. It's supposed to flatten one layer.

Of course x.then(function (xValue) { return Promise.of(Promise.of(xValue)) }) should be "equivelant" to Promise.of(x)