Not sure if this is correct, but: This might actually be (perhaps accidentally) one step closer to allowing promises for thenables in a cleaner way if the need arises in the future.
Since its impossible to create a promise for a promise now, it would be theoretically possible to just
.thenunwrap "true" promises only once
resolvecast thenables into promises that recursively unwrap thenables
and be done.� You'd have
Promise.of- wraps thenables, returns promises, wraps other values
resolve- converts thenables to recursively unwrapping promises, returns promises, wraps other values
.then(f, r)- for values returned by the handlers: recursively unwraps thenables, unwraps promises once, wraps other values
After that, you could use
.then in a monadic way, provided you remember to protect thenables with
Promise.of (should not be a problem with typed compile-to-js languages). e.g.
p.then(x => Promise.of(thenable)) You could also implement
Previously you'd have to make
Promise.cast the same before making
.then unwrap a single level. Alternatively, you'd have to introduce
.chain and have a confusingly dual API (chain/then, resolve/cast).