Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

interlude

clux6.4kMIT2.0.0

Functional JavaScript library

utility, set, functional, haskell, partial, curry, zipWith, FP, ES6

readme

Interlude

npm status build status dependency status coverage status

Interlude is a functional ES6 based JavaScript library inspired by Haskell. It's aims to simplify and abstract common patterns by providing a set of common higher order functions.

Usage

Use it with qualified imports with the yet unfinished module import syntax or attach it to the short variable of choice. For selling points, here's how it will look with ES7 modules.

import { range, pow, times, all, eq, comparing, zipWith, zipWith3, iterate, gcd, uniqueBy, iterate, interval } from 'interlude'

range(5).map(pow(2));
// [ 1, 4, 9, 16, 25 ]

var nested = [ [ 1, 3, 2 ], [ 2, 2 ], [ 1, 4, 2, 3 ] ];
nested.filter(all(eq(2)));
// [ [2, 2] ]

// outer sort by property
nested.sort(comparing('length'));
// [ [ 2, 2 ], [ 1, 3, 2 ], [ 1, 4, 2, 3 ] ]

zipWith3((x, y, z) => x + y + z, [1,1,1,1,1], range(5), [1,0,0]);
// [ 3, 3, 4 ]

// Powers of two
iterate(8, 2, times(2));
// [ 2, 4, 8, 16, 32, 64, 128, 256 ]

// Pascal's Triangle
var pascalNext = (row) => zipWith((x, y) => x + y, row.concat(0), [0].concat(row));

iterate(6, [1], pascalNext);
// [ [ 1 ],
//   [ 1, 1 ],
//   [ 1, 2, 1 ],
//   [ 1, 3, 3, 1 ],
//   [ 1, 4, 6, 4, 1 ],
//   [ 1, 5, 10, 10, 5, 1 ] ]

// Prime numbers
var notCoprime = (x, y) => gcd(x, y) > 1;
uniqueBy(notCoprime, interval(2, 20));
// [ 2, 3, 5, 7, 11, 13, 17, 19 ]

Interlude is merely a stable front for three re-exported modules:

interlude
├─── autonomy
├─── operators
└─── subset

These modules are of course requirable by themselves, and we encourage you to require them directly. The submodules are small (<150 lines each) and focused.

Regardless, you should read their short and independent APIs:

Additionally, two extra modules (which were not included in interlude due to their smaller likelihood of use) are also good fits. They do not overlap in API, and are highly recommended when needed. You may wish to read their short APIs as well.

Installation

$ npm install interlude

License

MIT-Licensed. See LICENSE file for details.

changelog

2.0.0 / 2016-01-28

  • ES6 rewrite
  • Bump autonomy to 2.0.0 (module reduced in size and scope for ES6)
  • Bump operators to 1.0.0 (module reduced in size and scope for ES6)
  • Bump subset to 1.0.0 (module reduced in size and scope for ES6)
  • TL;DR - a couple of functions removed from each library:
    • infrequently used stuff
    • badly optimizable variadic stuff using arguments
    • some variadic functions split into numbered versions (zip, range, ..)
    • stuff obsoleted by ES6

1.1.1 / 2015-11-15

  • Added .npmignore

1.1.0 / 2014-09-30

  • Bump autonomy to 1.0.0:
    • adds copy
    • replicate is now object safe

1.0.3 / 2014-07-25

  • Documentation and coverage release

1.0.2 / 2012-11-12

  • extend a blank copy of seq rather than require result of autonomy. (Was overwriting the cached require results of autonomy in linked installs)

1.0.1 / 2012-11-11

  • $() now a shortcut for deprecated $.seq

1.0.0 / 2012-10-24

  • retroactive inclusion of an overloaded version $.compare from subset

1.0.0 / 2012-10-20

  • interlude is now a stable front for autonomy, subset and operators
  • has, seq2, seq3, seq4, getDeep removed from autonomy
  • replicate is now array safe
  • get is now variadic and assumes the role of getDeep
  • wrappers excluded from exports because:
    • less stable API
    • less likelihood of use
  • subset includes isSubsetOf (retroactively available to previous versions)

0.7.0 / 2012-07-04

  • autonomy updated to 0.3.0 changing scan argument order
  • allow use on any node version

0.6.0 / 2012-07-03

  • wrappers updated to 0.2.0 removing either and guard

0.5.1 / 2012-06-30

  • include new (v0.2.0) autonomy which comes without operators + pow/log but with extend
  • operators included directly (now comes with pow/log + pow2/log2)
  • improve DOCS browsability and just api in general

0.5.0 / 2012-06-22

  • update wrappers to 0.1.0 (now close to done, has a lot more)

0.4.0 / 2012-06-17

  • use latest operators, 0.3 missed some extras
  • comparing/compare direction parameter is now the factor +1/-1 with +1 omittable
  • set operations + comparison/equality generalizations moved to subset module
  • everything else (must haves) moved into origin module, which re-exports operators.
  • trace/traceBy/wrap/once/memoize initial wrappers included via wrappers module
  • module basically just a re-export

0.3.0 / 2012-06-15

  • operators moved to own module (which now is bigger and better)
  • renamed collect to pluck to conserve (at least some) conventions
  • $.equality, $.comparing $.compare added
  • removed awful setters
  • delete/insert/deleteBy/insertBy now all modify input (insertBy didn't)
  • delete/deleteBy now only deletes first occurrence
  • difference/differenceBy introduced (non-modifying)
  • Data.List like API now dependency free, can be factored out
  • compose redone for performance and sensibility. See: seq, seq2, seq3, seq4.
  • experimental stuff removed from module.exports while it's in the works
  • tests moved from expresso to tap

0.2.0 / 2012-06-03

  • Data.List generic insert/delete/group/union/maximum/minimum/nub done

0.1.0 / 2012-06-02

  • First proper version under 'interlude'