Transforms the succesful value of a future by using a function stored in another future.
Transforms the succesful value of a future by using a function stored in another future.
const { of, rejected } = require('folktale/concurrency/future');
const inc = (x) => x + 1;
of(inc).apply(of(1)).listen({
onResolved: (value) => $ASSERT(value == 2)
});
rejected(inc).apply(of(1)).listen({
onRejected: (reason) => $ASSERT(reason === inc)
});
of(inc).apply(rejected(1)).listen({
onRejected: (reason) => $ASSERT(reason == 1)
});
apply(future) {
return this.chain(fn => future.map(fn));
}