- Node.js 7.4+
- bluebird
- ramda
(Promise filterCondition → Boolean, Iterable<any>) → Promise → Iterable<any>
(Promise filterCondition → Boolean, Iterable<any>) → Promise → Iterable<any>
Sequential filter.
(Promise mapFunction → any, Iterable<any>) → Promise → Iterable<any>
Sequential map.
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]))