functional_utils

0.0.2 • Public • Published

bitHound Overall Score bitHound Dependencies bitHound Code

Functional programming utils

This lib provides some utility functions that can be useful while writing code in node.js Basic test for usage of this module.

const Utils = require('@nodeart/functional_utils'),
      assert = require('assert');
 
//curry test
const curried = Utils.curry((...args) => args.length, 0, 1, 2, 3, 4);
assert.equal(curried(5, 6, 7, 8, 9), 10, 'Curry test done');
 
//pipe test
const piped = Utils.pipe(d => d * 2, d => d * 3, d => d * 4, d => d * 5);
assert.equal(piped(2), 240, 'Pipe test done');
 
//asyncPipe test
const asyncPiped = Utils.asyncPipe(
  res => assert.equal(res, 240, 'AsyncPipe test done'),
  (d, cb) => setTimeout(() => cb(* 2), 500),
  (d, cb) => setTimeout(() => cb(* 3), 500),
  (d, cb) => setTimeout(() => cb(* 4), 500),
  (d, cb) => setTimeout(() => cb(* 5), 500)
);
asyncPiped(2);
 
//compose test
const composed = Utils.compose(d => d / 5, d => d / 4, d => d / 3, d => d / 2);
assert.equal(composed(240), 2, 'Compose test done');
 
//asyncCompose test
const asyncComposed = Utils.asyncCompose(
  res => assert.equal(res, 2, 'AsyncComposed test done'),
  (d, cb) => setTimeout(() => cb(/ 5), 500),
  (d, cb) => setTimeout(() => cb(/ 4), 500),
  (d, cb) => setTimeout(() => cb(/ 3), 500),
  (d, cb) => setTimeout(() => cb(/ 2), 500)
);
asyncComposed(240);

Readme

Keywords

Package Sidebar

Install

npm i functional_utils

Weekly Downloads

1

Version

0.0.2

License

ISC

Last publish

Collaborators

  • ivan-tymoshenko
  • nodeartio