Methods

inner

compose(arguments) → (function() or Promise)

Compose regular functions or promises generating a final function.

  • Compose works from right to left.
  • If you compose one single promise the final result will be a promise too.
  • You can only compose functions with the same arity.

Example

const sum3 = a => a+3
const mult2 = a => a*2
const sum2Async = a => Promise.resolve(a+2) // Simulate async response

const sumAndMult = compose(sum3,mult2);
sumAndMult(1) // -> (1*2)+3 = 5

const sumAndMultAsync = compose(sum3,mult2,sum2Async);
await sumAndMultAsync(1) // -> ((1+2)*2)+3 = 9

Parameter

Name Type Optional Description

arguments

(function() or Promise)

 

N number of functions or promises.

Returns

(function() or Promise) 

function or Promise that execute the all composed ones.

inner

curry(function) → function()

Currify any function allowing the partial application of its arguments

Example

const sum = curry((a,b) = a+b);
const sum3 = sum(3);
sum3(3) // -> 6
sum(3,3) // -> 6
sum(3)(3) // -> 6

Parameter

Name Type Optional Description

function

function()

 

function with at least two arguments

Returns

function() 

curried function.

inner

mixCompose(chain, func)

Reducer function used by pipe and compose functions to compose sync and async functions

Parameters

Name Type Optional Description

chain

(function() or Promise)

 

a chain of functions or promises

func

(function() or Promise)

 

a new function or promise to add to the chain

inner

pipe(arguments) → (function() or Promise)

Compose regular functions or promises generating a final function.

  • Compose works from left to right.
  • If you compose one single promise the final result will be a promise too.
  • You can only compose functions with the same arity.

Example

const sum3 = a => a+3
const mult2 = a => a*2
const sum2Async = a => Promise.resolve(a+2) // Simulate async response

const sumAndMult = pipe(sum3,mult2);
sumAndMult(1) // -> (1+3)*2 = 8

const sumAndMultAsync = pipe(sum3,mult2,sum2Async);
await sumAndMultAsync(1) // -> ((1+3)*2)+2 = 10

Parameter

Name Type Optional Description

arguments

(function() or Promise)

 

N number of functions or promises.

Returns

(function() or Promise) 

function or Promise that execute the all composed ones.