foldable

Fold iterable data


Keywords
foldable, fold, reduce, reducing
License
GPL-3.0-only
Install
npm install foldable@0.0.1

Documentation

foldable

Fold any iterable.

npm install --save foldable

const fold = require('foldable')

const myStr = 'abc'
const myArr = [ 1, 2, 3 ]
const myObj = { a: 1, b: 2, c: 3 }

fold(myStr, 0, acc => acc + 1)
// => 3

fold(myArr, 0, (acc, value) => acc + value)
// => 6

fold(Object.entries(myObj), {}, (acc, [key, value]) => ({
  ...acc,
  [key]: value + 1
}))
// => { a: 2, b: 3, c: 4 }