Skip to content

kozakvoj/hofp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hofp - Higher-order functions for promises

Build Status

Dependencies

  • Node.js 7.4+
  • bluebird
  • ramda

API

reduce

(Promise filterCondition → Boolean, Iterable<any>) → Promise → Iterable<any>

filter

(Promise filterCondition → Boolean, Iterable<any>) → Promise → Iterable<any>

Sequential filter.

map

(Promise mapFunction → any, Iterable<any>) → Promise → Iterable<any>

Sequential map.

Usage

const H = require('hofp')

Using reject

const conditionReturningPromise = value =>
    P.resolve().then(() => value === "a" || value === "c");

H.reject(conditionReturningPromise, ["a", "b", "c", "d", "e"])
    .then(result => assert.deepEqual(result, ["b", "d", "e"]))

With filter

H.filter(conditionReturningPromise, ["a", "b", "c", "d", "e"])
    .then(result => assert.deepEqual(result, ["a", "c"]))

Using map

const mapFunction = value => P.resolve().then(() => value * value);

H.map(mapFunction, [1, 2, 3])
    .then(result => assert.deepEqual(result, [1, 4, 9]))

Using pipe

H.pipe([asyncFce1, asyncFce2, asyncFce3], [1, 2, 3, 4]);

Chaining with Ramda

const mapFunction = value => P.resolve().then(() => value * value);

P.resolve([1, 2, 3, 4])
    .then(R.map(value => value * value))
    .then(R.curry(map)(mapFunction))
    .then(R.filter(n => n % 2 === 0))
    .then(result => assert.deepEqual(result, [16, 256]))

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published