func-fns
v0.0.10
Published
Functional utils for your functional needs.
Downloads
2
Maintainers
Readme
func-fns
Functional utils for your functional needs.
npm i func-fns
filter fns
keep
import keep from 'func-fns/filter/keep'
const res = ['foo', 'bar', 'baz'].filter(keep(1))
console.log(res) // ['bar']
remove
import remove from 'func-fns/filter/remove'
const res = ['foo', 'bar', 'baz'].filter(remove(1))
console.log(res) // ['foo', 'baz']
uniq
import uniq from 'func-fns/filter/uniq'
const res = ['foo', 'foo', 'bar', 1, 1].filter(uniq())
console.log(res) // ['foo', 'bar', 1]
flatMap fns
insert
import insert from 'func-fns/flatMap/insert'
const res = ['foo', 'bar', 'baz'].flatMap(insert('foo', 1))
console.log(res) // ['foo', 'foo', 'bar', 'baz']
truthy
import truthy from 'func-fns/flatMap/truthy'
const res = ['foo', undefined, 'baz', null].flatMap(truthy())
console.log(res) // ['foo', 'baz']
map fns
length
import length from 'func-fns/map/length'
const res = ['foo', ['bar', 'baz']].map(length())
console.log(res) // [3, 2]
replace
import replace from 'func-fns/map/replace'
const res = ['foo', 'bar', 'baz'].map(replace(1, 'foo'))
console.log(res) // ['foo', 'foo', 'baz']
transpose
import transpose from 'func-fns/map/transpose'
const res = ['foo', 'bar', 'baz'].map(transpose(1, 2))
console.log(res) // ['foo', 'baz', 'bar']
key
import key from 'func-fns/map/key'
const res = [{ id: 'foo' }, { id: 'bar' }].map(key('id'))
console.log(res) // ['foo', 'bar']
reduce fns
shuffle
import shuffle from 'func-fns/reduce/shuffle'
const res = [1, 2, 3, 4, 5].reduce(...shuffle())
console.log(res) // will be shuffled, eg, [5, 2, 1, 4, 3]
import sum from 'func-fns/reduce/sum'
const res = [1, 2, 3].reduce(sum())
console.log(res) // 6