flatmap-fns
v0.0.3
Published
Functional utils for your flat mapping needs.
Downloads
167
Maintainers
Readme
flatmap-fns
Functional utils for your flat mapping needs.
npm i flatmap-fns
insert
import insert from 'flatmap-fns/insert'
const res = ['foo', 'bar', 'baz'].flatMap(insert('foo', 1))
console.log(res) // ['foo', 'foo', 'bar', 'baz']
keep
import keep from 'flatmap-fns/keep'
const resA = ['foo', 'bar', 'baz'].flatMap(keep(1))
console.log(resB) // ['bar']
const resB = ['foo', 'bar', 'baz'].flatMap(keep(1, 2))
console.log(resB) // ['bar', 'baz']
key
import key from 'flatmap-fns/key'
const res = [{ id: 'foo' }, { id: 'bar' }].flatMap(key('id'))
console.log(res) // ['foo', 'bar']
length
import length from 'flatmap-fns/length'
const res = ['foo', ['bar', 'baz']].flatMap(length())
console.log(res) // [3, 2]
remove
import remove from 'flatmap-fns/remove'
const resA = ['foo', 'bar', 'baz'].flatMap(remove(1))
console.log(resA) // ['foo', 'baz']
const resB = ['foo', 'bar', 'baz'].flatMap(remove(0, 1))
console.log(resB) // ['baz']
replace
import replace from 'flatmap-fns/replace'
const res = ['foo', 'bar', 'baz'].flatMap(replace(1, 'foo'))
console.log(res) // ['foo', 'foo', 'baz']
resize
import resize from 'flatmap-fns/resize'
const resA = [1].flatMap(resize(3))
console.log(resA) // [1, undefined, undefined]
const resB = [1, 2, 3, 4, 5].flatMap(resize(3))
console.log(resB) // [1, 2, 3]
rotate
import rotate from 'flatmap-fns/rotate'
const resA = [1, 2, 3].flatMap(rotate())
console.log(resA) // [3, 1, 2] - default is to rotate right by one step.
const resB = [1, 2, 3].flatMap(rotate({ direction: 'left', steps: 2 }))
console.log(resB) // [3, 1, 2]
shuffle
import shuffle from 'flatmap-fns/shuffle'
const res = [1, 2, 3, 4, 5].flatMap(shuffle())
console.log(res) // will be shuffled, eg, [5, 2, 1, 4, 3]
sum
import sum from 'flatmap-fns/sum'
const res = [1, 2, 3].flatMap(sum())
console.log(res) // [6]
transpose
import transpose from 'flatmap-fns/transpose'
const res = ['foo', 'bar', 'baz'].flatMap(transpose(1, 2))
console.log(res) // ['foo', 'baz', 'bar']
truthy
import truthy from 'flatmap-fns/truthy'
const res = ['foo', undefined, 'baz', null].flatMap(truthy())
console.log(res) // ['foo', 'baz']
uniq
import uniq from 'flatmap-fns/uniq'
const res = ['foo', 'foo', 'bar', 1, 1].flatMap(uniq())
console.log(res) // ['foo', 'bar', 1]