hofp
[![Build Status](https://travis-ci.org/kozakvoj/hofp.svg?branch=master)](https://travis-ci.org/kozakvoj/hofp)
Last updated 3 years ago by kozakvoj .
Original npm · Tarball · package.json
$ cnpm install hofp 
SYNC missed versions from official npm registry.

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

Current Tags

  • 0.7.0                                ...           latest (3 years ago)

11 Versions

  • 0.7.0                                ...           3 years ago
  • 0.6.0                                ...           3 years ago
  • 0.5.0                                ...           3 years ago
  • 0.4.0                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.4                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 3
Dependencies (2)
Dev Dependencies (3)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |