enchain

0.0.1 • Public • Published

enchain

Build Status

Browser support

There are cases when you may prefer method chaining API over plain functions. Libraries like jQuery and underscore include chaining facilities with them to address these use cases, although chaining is different problem and can (and there for should) be solved separately. Enchain solves just a chaining problem so libraries can concentrate on their actual problems and let users figure how they wanna chain them.

API

var enchain = require("enchain")
var reducers = require("reducers")
var chain = enchain(reducers)
 
 
chain([ 1, 2, 3, 4, 5, 6 ]).
  map(function(x) { return x + 1 }).
  filter(function(x) { return x % 2 }).
  concat([ "a", "b" ]).
  into([]).
  valueOf() // will return actual value rather then chainable DSL
 
// => [ 3, 5, 7, 'a', 'b' ]

Note that result of each method call is a chainable DSL, and in order to get actual result .valueOf() needs to be called. Although second set of functions maybe provided to make valueOf() call implicit:

var enchain = require("enchain")
var reducers = require("reducers")
var chain = enchain(reducers, {
  print: reducers.print,
  fold: reducers.fold
})
 
chain([ 1, 2, 3, 4, 5, 6 ]).
  map(function(x) { return x + 1 }, 3).
  filter(function(x) { return x % 2 }).
  fold(function(x, y) { return x + y }, 0)
 
// => 15

Install

npm install enchain

Readme

Keywords

none

Package Sidebar

Install

npm i enchain

Weekly Downloads

1

Version

0.0.1

License

none

Last publish

Collaborators

  • gozala