Transforms the succesful value of a future by using a function stored in another future.
This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.
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));
}