Hacker News new | ask | show | jobs
by dasyatidprime 1822 days ago
So, just out of curiosity: I know in ECMAScript this is probably mainly for the purpose of giving you a convenient way to lift either (α → β) or (α → Promise β) into (Promise α → Promise β) without static typing or having two "then" functions, by forcing β and Promise β to be disjoint. It also allows looser composition underneath, since you can choose which kind of return to provide at runtime without having to re-wrap the bare case manually. But are there any other reasons for Promise of Promise to be squashed away like that?
1 comments

Apart from simplicity, it was designed to be used with "thenables". If the value that a Promise resolved with had a `then()` member, the value would be treated like a first-party Promise. So even if there was a separate fmap-then and bind-then, the fmap-then would have to deal with thenables and act like bind-then anyway.

There's a bunch of history in [1], particularly [2] and [3], if you care to read them.

[1]: https://github.com/promises-aplus/promises-spec/issues

[2]: https://github.com/promises-aplus/promises-spec/issues/75

[3]: https://github.com/promises-aplus/promises-spec/issues/94