0.7.0 • Published 6 years ago

hofp v0.7.0

Weekly downloads
34
License
-
Repository
-
Last release
6 years ago

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]))
0.7.0

6 years ago

0.6.0

6 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago