bimap

Transforms both successful and failure values in a Future, without touching its state.

Signature

value(rejectionTransformation, successTransformation)
(Future 'f 's).(('f) => 'f2, ('s) => 's2) => Future 'f2 's2

Documentation

Transforms both successful and failure values in a Future, without touching its state.

Example:

const { of, rejected } = require('folktale/concurrency/future');

const inc = (x) => x + 1;
const dec = (x) => x - 1;

of(1).bimap(inc, dec).listen({
  onResolved: (x) => $ASSERT(x == 0)
});

rejected(1).bimap(inc, dec).listen({
  onRejected: (x) => $ASSERT(x == 2)
});

Properties

Source Code

Defined in source/concurrency/future/_future.js at line 24, column 0
bimap(rejectionTransformation, successTransformation) {
    let deferred = new Deferred();      // eslint-disable-line prefer-const
    this.listen({
      onCancelled: ()     => deferred.cancel(),
      onRejected:  reason => deferred.reject(rejectionTransformation(reason)),
      onResolved:  value  => deferred.resolve(successTransformation(value))
    });

    return deferred.future();
  }
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/)