fp-array
fp-array
is a group of functions to do declarative programming in a more convenient way than in Array.prototype
Installation
$ npm install fp-array
Syntax
const map = mapconst filter = filterconst reduce = reduceconst arr = ... ... ...
Examples
#map()
const arr = 1 2 3// callbacksconst increment = n + 1const double = n * 2 // ['4', '6', '8'] arr // [1, 2, 3]
Notes
- Iterates only one time over
arr
- Inmutable:
arr
has not mutated, a new Array is returned whenresult()
- Declarative: Easy to read syntax
#filter()
const arr = 1 'a' true 6 0 4 undefined 10 const number = typeof n === 'number'const greaterThan4 = n > 4const even = n % 2 === 0 // [6, 10] arr // [1, 'a', true, 6, 0, 4, undefined, 10]
Same notes than before applies.
#reduce()
const arr = 1 2 3 // 11
reduce()
works exactly like the original except now is outside the Array.prototype
More examples in tests.
Have any idea ?
Open an issue or say hi on twitter: @juliomatcom
MIT Licensed
Copyright (c) 2016 Julio César Martín