apply

Applies the function in the left task to the value on the right task. The left task is ran to completion before the right task is started.

This feature is experimental!

This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.

Signature

value(task)
forall e, v1, v2:
  (Task e ((v1) => v2)).(Task e v1) => Task e v2

Documentation

Applies the function in the left task to the value on the right task. The left task is ran to completion before the right task is started.

Note that the right task isn't ran if the left task contains a failure.

If any of the tasks fail, the result will be that failure. Likewise, if any of the tasks is cancelled, the result will be that cancellation.

Example:

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

const result1 = await of(x => x + 1).apply(of(1)).run().promise();
$ASSERT(result1 == 2);

try {
  const result2 = await of(x => x + 1).apply(rejected(1)).run().promise();
  throw 'never happens';
} catch (error) {
  $ASSERT(error == 1);
}

Properties

Source Code

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