Skip to content

abstract-tools/foldable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 }

Releases

No releases published

Packages

No packages published