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

Package detail

@ndhoule/foldl

ndhoule69.7kMIT2.0.1

Apply a function to each value in a collection, accumulating the results into a single return value.

fold, reduce, component

readme

foldl CI

Apply a function to each value in a collection, accumulating the results into a single return value.

Installation

$ component install ndhoule/foldl
$ npm install @ndhoule/foldl

API

reduce(iterator : Function, accumulator : *, collection : Array|Object)

Reduces all the values in a collection down into a single value. Does so by iterating through the collection from left to right, repeatedly calling an iterator function and passing to it four arguments: (accumulator, value, index, collection).

foldl(function(total, n) {
  return total + n;
}, 0, [1, 2, 3]);
//=> 6

var phonebook = { bob: '555-111-2345', tim: '655-222-6789', sheila: '655-333-1298' };

foldl(function(results, phoneNumber) {
 if (phoneNumber[0] === '6') {
   return results.concat(phoneNumber);
 }
 return results;
}, [], phonebook);
// => ['655-222-6789', '655-333-1298']

License

Released under the MIT license.

changelog

2.0.1

  • Bump @ndhoule/each, @ndhoule/keys dependency to fix Browserify builds

2.0.0

  • Remove Component/Duo support

1.0.3

  • Fix Duo compatibility

1.0.2

  • Ensure npm@>=2.7.0 on Travis CI
  • Use scoped package
  • Update Makefile
  • Move git dependencies to npm packages
  • Update installation instructions

1.0.1

  • Tests passing on IE6-8
  • Remove IE6-8 string iteration guarantee
  • Remove duplicate test

1.0.0

Initial release