Skip to content

Latest commit

 

History

History
112 lines (74 loc) · 3.03 KB

task.md

File metadata and controls

112 lines (74 loc) · 3.03 KB

Task

A Task makes it easy to model asynchronous operations that may fail, like HTTP requests or reading/writing to a files/databases

Implements: Monad, Semigroup

Task(f)

Task constructor

Param Type Description
f function A function that takes two arguments reject and resolve, which in turn are functions. Function f normally initiates an asynchronous work or one that has effects, and then, once it completes, either calls the resolve function to resolve the Task or else rejects it.

Task.of(v)

Task constructor that creates a Task which immediately resolves

Param Type Description
v any value that is passed to the resolve function

Task.rejected(v)

Task constructor that creates a Task which immediately gets rejected

Param Type Description
v any value that is passed to the rejected function

Task.fork(reject, resolve)

Executes the Task

Param Type Description
reject function Function to be called when the Task is rejected
resolve function Function to be called when the Task is resolved

Task.toString()

Get a stringified version of the Task

Task.map(f)

Apply the function f to value of a successfully resolved Task

Param Type Description
f function Function

Task.getValue()

Get the function within the Task

Task.ap(t)

Applys the successful value of the Task t to the successful value(a function) of the current Task

Param Type Description
t Task Task with function as the second element

Task.concat(t)

Concat the current Task with the passed one and get a new Task. Which when resloved would get the successfull result of both the tasks.

Param Type Description
t Task Task to concat

Task.chain(f)

Chain together many computations that return a Task

Param Type Description
f function Function that returns another Task

Task.toPromise()

Converts the current task to a Promise