apply

Transforms the succesful value of a future by using a function stored in another future.

Signature

value(future)
(Future 'f 's).(Future 'f (('s) => 's2)) => Future 'f 's2

Documentation

Transforms the succesful value of a future by using a function stored in another future.

Example:

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)
});

Properties

Source Code

Defined in source/concurrency/future/_future.js at line 24, column 0
apply(future) {
    return this.chain(fn => future.map(fn));
  }
Stability
stable
Licence
MIT
Module
folktale/concurrency/future/_future
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)