foldable
v0.0.1
Published
Fold iterable data
Downloads
18
Maintainers
Readme
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 }