0.0.1 • Published 5 years ago

foldable v0.0.1

Weekly downloads
4
License
GPL-3.0-only
Repository
github
Last release
5 years ago

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 }