Core

converge

Apply a list of function (extract functions) on the same input and use the results as parameters for a final accumulator function.

converge
Parameters
accFn ((Function | Array<Function>)) Accumulator or final aggreate function
extractFn ((Function | Array<Function>)) Functions to be applied on input
params (...any) Function params
Returns
any:
Example
const divide = () => {}
const sum = () => {}
const count = () => {}

converge(divide, [sum, count], [1, 2, 3, 4, 5, 6, 7])
// => 4

forEach

Call fn over each element of an array

forEach
Parameters
fn ((Function | Array<Function>)) Iterator function
source (Array) Source array
Returns
undefined:

i

Identity function

i
Parameters
input (any) Source input
Returns
any:

map

Iterates over an array and applies a function on each element, returning a new array with the transformed elements.

map
Parameters
fn ((Function | Array<Function>)) Transform function called on each element
input (Array) Source array to iterate over
Returns
Array: Returns new instance
Related
mapMatrix
Example
const inc = x => x + 1

map(inc, [1, 2])
// => [2, 3]

map([inc, inc], [1, 2])
// => [3, 4]

mapMatrix

Matrix version of "map". Iterates over a two-dimensional array and applies a function on each element, returning a new matrix with the transformed elements.

mapMatrix
Parameters
fn ((Function | Array<Function>)) Transform function called on all elements
Related
map
Example
const inc = x => x + 1

mapMatrix(inc, [[1, 2], [3, 4]])
// => [[2, 3], [4, 5]]

mapMatrix([inc, inc], [[1, 2], [3, 4]])
// => [[3, 4], [5, 6]]

pipe

Performs left-to-right function composition. The leftmost function may have any arity, the remaining functions must be unary.

pipe
Parameters
firstFn (Function) First function in transform chain
restFn (Array<Function>) Remaining functions
input (Array) First function arguments
Returns
any:
Related
pipeP
Example
pipe(inc, inc)(2)
// => 4

read

Get value from obj property

read
Parameters
path ((string | Array<string>)) Property name or dot path of props
defaultValue (any) Value to return if not found
input (Object) Source object
params (...any) Function params
Returns
any:
Example
read("lorem")({ lorem: "ipsum" })
// => "ipsum"

read("not-exist")({ lorem: "ipsum" })
// => undefined

read("not-exist-with-default", "dolor", { lorem: "ipsum" })
// => "dolor"

read(["a", "b"])({ a: { b: "c" } })
// => "c"

read(["a", "test"])({ a: { b: "c" } })
// => undefined

reduce

Apply a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.

reduce
Parameters
fn (Function) Reduce function
defaultAcc (Object) Default accumulator value
input (Array) Source input
params (...any) Function params
Returns
any:
Example
const sum = (acc, item) => acc + item

reduce(sum, 0, [1, 2])
// => 3

same

Curried funtion that always returns the input given

same
Parameters
input (any) Something, anything
Returns
any:

write

Shallow clone of an object, setting or overriding a property with the given value

write
Parameters
key (string)
value (any)
input (Object)
Returns
Object:
Example
write( "a", "lorem" )( { b: "ipsum" } )
// => { a: "lorem", b: "ipsum" }

Array

bottom

Get all but first element from array

bottom
Parameters
params (...any)
limit (number) How many elements from the bottom
source (Array) The source
Returns
any:
Example
bottom([1, 2, 3])
// => [1, 2]

bottom([1]), bottom([])
// => []

bottom(2, [2, 3])
// => [2, 3]

bottom(2)([1, 2, 3])
// => [2, 3]

count

Count the number of elements that satisfies a function

count
Parameters
fn ((Function | Array<Function>)) Match function
source ((Array | Object)) If object passed, Object.entries will be iterated over
Returns
number:
Related
countWith
Example
const scores = [{
 name   : "Bob",
 score  : 1,
 subject: "Math"
}, {
 name   : "Alice",
 score  : 10,
 subject: "Math"
}, {
 name   : "Hatter",
 score  : 10,
 subject: "Math"
}]

count(element => element.score === 10)(scores)
// => 2

countWith

Count elements in array or object that match object

countWith
Parameters
subset (Object) Match object
source ((Array | Object)) If object passed, Object.entries will be iterated over
Returns
number:
Related
count
Example
const scores = [{
 name   : "Bob",
 score  : 1,
 subject: "Math"
}, {
 name   : "Alice",
 score  : 10,
 subject: "Math"
}, {
 name   : "Hatter",
 score  : 10,
 subject: "Math"
}]

countWith(
  { score: gt(5) },
  scores
)
// => 2

distinct

Remove repeating values

distinct
Parameters
input (Array) Source input array
Returns
Array:
Example
distinct([1, 1, 2])
// => [1, 2]

filter

Filter elements matching a predicate

filter
Parameters
fn (Function) Predicate functions
Returns
Array:

filterWith

Filter elements matching an object

filterWith
Parameters
subset (Object) The function
Returns
Array:

find

Find the first element that matches a predicate

find
Parameters
fn ((Function | Array<Function>)) Match function applied to each element
notFoundDefault (any) Return if no item found
source (Array) Source array to iterate over
Returns
any:
Related
findWith
Example
const comments = [{id: 1, body: ""}, {id: 2, body: "dolor"}]

find(item => item.body === "dolor")(comments)
// => {id: 2, body: "dolor"}

find([get("body"), equals("dolor")], null, comments)
// => {id: 2, boby: "dolor" }

findWith

Find the first element that matches an object

findWith
Parameters
subset (Object) Match object
notFoundDefault (any) Return if no item found
source (Array) Source array to iterate over
Returns
any: First element found or undefined
Related
find isMatch
Example
const comments = [{id: 1, body: ""}, {id: 2, body: "dolor"}]

findWith({id: 2})(comments)
// => {id: 2, body: "dolor"}

find({id: "404"}, {default: "value"}, comments)
// => {default: "value"}

first

Get left most element of array

first
Parameters
input (Array) The source
Returns
any:
Example
first([1, 2, 3])
// => 1

first([])
// => undefined

flatten

Recursively concat all arrays intro a single array

flatten
Parameters
input ((Array | Object)) Array or Object to flatten
Returns
Array: 1 level deep array
Example
flatten([1, [2], [3, [4]]])
// => [1, 2, 3, 4]

flatten({test: {a: 1, b: {c: 2}}})
// => {
 test__a: 1,
 test__b__c: 2
}

last

Get right most element of array

last
Parameters
input (Array) The source
Returns
any:
Example
last([1, 2, 3])
// => 3
last([])
// => undefined

partition

Split an array based on a predicate function. Take A[] and return a two-tuple of A[]s. The first element of the tuple consists of elements for which the predicate returned true, the second of elements for which it returned false.

partition
Parameters
fn (Function) A predicate function.
Returns
Array<Array, Array>:
Example
partition(x => x % 2 === 0)([1, 2, 3, 4, 5])
// => [[2, 4], [1, 3, 5]]

partitionWith

Split an array based on object matching Take A[] and return a two-tuple of A[]s. The first element of the tuple consists of elements for which the predicate returned true, the second of elements for which it returned false.

partitionWith
Parameters
subset (object) A predicate function.
Returns
Array<Array, Array>:
Example
partitionWith({comments: is}, [{id: 1}, {id: 2, comments: []}])
// => [[{id: 1}], [{id: 2, comments: []}]]

pluck

Returns a partial copy of an object containing only the keys specified. If the key does not exist, the property is ignored.

pluck
Parameters
params (...any)
Returns
(Object | Array<Object>):
Example
pluck(
 ["id", "name"],
 {
   id: 2,
   name: "lorem",
   description: "lorem ipsum"
 }
)
// => {id: 2, name: lorem}

remove

Remove element(s) from array by value or by predicate

remove
Parameters
params (...any)
Name Description
params.fn (Function | any) Value to remove or predicate to match
params.input Array
Returns
Array:
Example
remove(3)([1, 2, 3])
// => [1, 2]

remove(_ => _ === 3)([1, 2, 3])
// => [1, 2]

removeWith

Remove element(s) by matching object

removeWith
Parameters
params (...any)
Name Description
params.subset Object Match object
params.input Array Source array
Returns
Array:
Example
removeWith(
  {
    tag: not(is)
  },
  [
    {id: 1, tag: 2},
    {id: 2}
  ]
)
// => [{id: 1, tag: 2}]

sort

Sort primitive array

sort
Parameters
params (...any)
Name Description
params.direction string (default "asc")
params.input Array
Returns
Array:
Related
sortBy sortWith
Example
sort([3, 2, 1])
// => [1, 2, 3]

sort("desc", [1, 2, 3])
// => [3, 2, 1]

sortBy

Sort array using custom function

sortBy
Parameters
fn (Function) Sort function
input (Array)
Returns
Array:
Related
sort sortWith
Example
sortBy((a, b) => a.id - b.id, [{id: 2}, {id: 1}])
// => [{id: 1}, {id: 2}]

sortWith

Sort an array of objects by multiple fields

sortWith
Parameters
subset (Object)
source (Array)
params (...any)
Returns
Array:
Related
sort sortBy
Example
sortWith({position: "asc"},
  { id: 1, position: 3 },
  { id: 2, position: 2 },
  { id: 3 },
  { id: 4, position: 5 },
  { id: 5, position: null },
])
// [
//  { id: 2, position: 2 },
//  { id: 1, position: 3 },
//  { id: 4, position: 5 },
//  { id: 5, position: null },
//  { id: 3 },
//]

top

Get all but last element from array

top
Parameters
limit (number = 1) Item count
source (Array)
Returns
any:
Example
top([1, 2, 3])
// => [1, 2]

top([1]), top([])
// => []

top(2, [2, 3])
// => [2, 3]

top(2)([1, 2, 3])
// => [2, 3]

Boolean

all

Test if all elements of array satisfy a function

all
Parameters
fn ((Function | Array<Function>)) Test function called on each elements
source (Array) Source array to iterate over
Returns
boolean: True if all elements pass, otherwise false
Related
allWith any anyWith
Example
all(isNumber)([1, 2, 3])
// => true

all(is, [1, "asd", null])
// => false

allWith

Test if all elements in array match object

allWith
Parameters
subset (object) Match object
source (Array) Source array to iterate over
Returns
boolean: True if all elements match, otherwise false
Related
all any anyWith isMatch
Example
allWith(isNumber)([1, 2, 3])
// => true

allWith(is, [1, "asd", null])
// => false

any

Test if at least one element in array matches predicate

any
Parameters
fn ((Function | Array<Function>)) Predicate function
source (Array) Source array to iterate over
Returns
boolean: True if at least one element passes, otherwise false
Related
anyWith all allWith
Example
any(isNumber)([1, "string", NaN])
// => true

any([get("id"), is], [{title: ""}, {}])
// => false

anyWith

Test if at least one element in array matches object

anyWith
Parameters
subset (object) Match object
source (Array) Source array to iterate over
Returns
boolean: True if at least one element pass, otherwise false
Related
any all allWith isMatch
Example
anyWith({ comments: is })([{id: 1}, {id: 2, comments: []}])
// => true

anyWith({ tags: is })([{id: 1}, {id: 2, comments: []}])
// => false

is

Test if something is not null, undefined or NaN

is
Parameters
input (any) Source variable
Returns
boolean:
Example
is(null)      // => false
is(0)         // => true
is(undefined) // => false
is("")        // => true
is(false)     // => true
is(NaN)       // => false

isBetween

Check if value is inside open or closed interval

isBetween
Parameters
left (number) Left limit
right (number) Right limit
arg3 (Object = {}) Props
Name Description
arg3.closed boolean (default false) If intervals is closed or not
Returns
boolean:
Example
between(2, 5)(5)
// => false

between(2, 5, {closed: true})(5)
// => true

isEmpty

Check if variable is considered empty

isEmpty
Parameters
input (any) Source input
Returns
boolean: True if empty, False otherwise
Example
isEmpty({})                // true
isEmpty(1)                 // false
isEmpty(false)             // false
isEmpty("")                // true
isEmpty(null)              // true
isEmpty(undefined)         // true
isEmpty([])                // true
isEmpty(NaN)               // true
isEmpty(/[A-z]/)           // false
isEmpty(new Date())        // false
isEmpty(() => {})          // false
isEmpty(Promise.resolve()) // false

isEqual

Check if a tripple-equals b (accounts for null, undefined and NaN)

isEqual
Parameters
a (any) First value
b (any) Second value
Returns
boolean:
Example
equal(2)(2)
// => true

equal("2")(2)
// => false

equal(NaN)(NaN)
// => true

equal([1])([1])
// => false

isMatch

Determines if one object's properties are equal to another

isMatch
Parameters
subset (object) Set of properties that should match
source (object) Object matching against
Returns
boolean: True if all "subset" properties are of equal (shallow compare) value to properties in "source" object, otherwise false
Example
isMatch({
 id: 2,
 parentId: null,
})({
 id: 2,
 parentId: null
 name: "John",
})
// true

isMatch({
 "!parentId": null,
 "name": "John",
})({
 id: 2,
 parentId: null,
 name: "John",
})
// false

when

Functional if-then-else

when
Parameters
params (...any)
ifFn (Function)
thenFn (Function)
elseFn (Function = i)
source (any)
Returns
any:
Example
when(isEven, increment, decrement)(5)
// => 6

when(isOdd, increment)(6)
// => 6

Object

keys

Get list with names of all own properties

keys
Parameters
input ((Array | Object)) Array or Object to extract keys from
Returns
Array<string>: List of property names
Example
keys(["lorem", "ipsum"])
// => ["0", "1"]

keys({ foo: "bar", lorem: "ipsum"})
// => ["foo", "lorem"]

keys("foo"), keys(12), keys(null), etc
// => []

merge

Combine from left to right, 2 or more objects into a new single one. Properties will be shallow copied. Those with the same name will be overwriten by right most object.

merge
Parameters
input (Array<Object>) Array of objects
params (...any) Function params
Returns
Object:
Example
merge({a: "lorem"}, {b: "ipsum", c: 41}, {c: 42, b: undefined})
// => { a: "lorem", b: "ipsum", c: 42 }

pick

Returns a new list by extracting the same named property off all objects in the source list

pick
Parameters
params (...any)
Returns
Array:
Example
pick("position")([{id: 1, position: 3}, {id:2, position: -1}])
// => [3, -1]

zipToObject

Create an object from two arrays, one containing keys, the other values. Both arrays will be trimmed to the smallest length.

zipToObject
Parameters
keys (Array)
values (Array)
Returns
Object:
Example
zipToObject([a, b])([1, 2]) // => { a: 1, b: 2 }
zipToObject([a], [1, 2]) // => { a: 1 }

isDeepEqual

Determine if two variables are structurally equal

isDeepEqual
Parameters
a (any) Source input
b (any) Other source input
params (...any)
Returns
boolean: True if inputs are structurally equal, false otherwise
Related
clone
Example
deepEqual(
{b: 3, a: 2},
{a: 2, b: 3}
)
// => true

deepEqual(
{a :[1, 2]}
)(
{a: [2, 1]}
)
// => false

elapsedTime

Calculate elapsed time between to dates. In days, hours, minutes and seconds

elapsedTime
Parameters
startDate (Date) Start date
endDate (Date) End date
Returns
object:
Example
elapsedTime(
  new Date("June 1, 2018 00:00:00"),
  new Date("June 1, 2018 03:24:00")
)
// => { days: 0, hours: 3, minutes: 24, seconds: 0 }

groupBy

Group an array of objects by field.

groupBy
Parameters
field (string) The field to index by. Value will be cast to string before indexing.
source (Array) Input array
Returns
Array<Array>:
Example
groupBy("user_id")([
  {id: 1, user_id: 2},
  {id: 2, user_id: 3},
  {id: 3, user_id: 2},
  {id: 4, user_id: null},
] )
// => [
//   [{id: 1, user_id: 2}, {id: 3, user_id: 2}],
//   [{id: 2, user_id: 3}],
//   [{id: 4, user_id: null}],
// ]

indexBy

Index an array of objects by field. Only truthy fields will be indexed.

indexBy
Parameters
field (string) The field to index by
source (Array) Input
Returns
object:
Example
indexBy("id")([
  {id: 1, user_id: 2},
  {id: 2, user_id: 3},
])
// => {
//   1: {id: 1, user_id: 2},
//   2: {id: 2, user_id: 3},
// }

byArray

Count the number of occurances of each element

byArray
Parameters
input (Array) Source input
Returns
Object:

byKey

Count the number of occurances of each object by a field

byKey
Parameters
field (string) The field
Returns
Object:

hist

Determine the count of all field's distinct values in a list of objects (aka histogram)

hist
Parameters
field (string) Field name to count
source (Array<Object>) Array of objects
Returns
Object:
Example
const scores = [{
 name   : "Bob",
 score  : 1,
 subject: "Math"
}, {
 name   : "Alice",
 score  : 10,
 subject: "Math"
}, {
 name   : "Hatter",
 score  : 10,
 subject: "Math"
}]

hist( "score" )( scores )
// => { "1": 1, "10": 2 }

protoChain

Return an array of constructor function names based on the prototype chain

protoChain
Parameters
input (Object) Source input
acc (Array<string> = []) Accumulator array
Returns
Array<string>:

tryCatch

Replicate try/catch using a tryer and catcher function

tryCatch
Parameters
tryer (Function) Try to do something with source input
catcher (Function) Run if tryer throws exception
Returns
any:
Example
tryCatch(inc)(10)
// => 11

tryCatch(
  () => { throw new Error("Tryer error") },
  (error, source) => inc(source)
)(10)
// => 11

type

From ramda: Gives a single-word string description of the (native) type of a value, returning such answers as "Object", "Number", "Array", or "Null".

Does not attempt to distinguish user Object types any further, reporting them all as "Object".

type
Parameters
input (any) Something to check type on
Returns
string:
Example
type({})                // "Object"
type(1)                 // "Number"
type(false)             // "Boolean"
type("s")               // "String"
type(null)              // "Null"
type(undefined)         // "Undefined"
type([])                // "Array"
type(/[A-z]/)           // "RegExp"
type(new Date())        // "Date"
type(() => {})          // "Function"
type(Promise.resolve()) // "Promise"

throttle

Create a wrapper function that is invoked once every time interval, regardless of how many times is called.

throttle
Parameters
fn (Function)
props (Object?)
Name Description
props.wait number (default 50) Time in milliseconds between "fn" invokations
props.hasLastCall boolean (default false) If should call "fn" after wrapper is no longer called
Returns
Function:
Example
const thottledMouseMove = throttle(mouseMove, { wait: 100 })

// render
<input onMouseMove={thottledMouseMove} ... />

debounce

Create a wrapper functions that is invoked only after some time since the last call.

debounce
Parameters
fn (Function)
props (Object?)
Name Description
props.wait number (default 50) Time in milliseconds to wait until invoke
Returns
Function: Wrapper function that calls fn after wait passed without calling
Example
const debouncedAutocomplete = debounce(autocompleteFromAPI, { wait: 100 })

// render
<input onChange={debouncedAutocomplete} ... />

isURI

Check if a string is a valid URI based on RFC3986

isURI
Parameters
input (string)
Returns
boolean:
Example
isURI("lorem")
// false

isURI("http://www.ietf.org/rfc/rfc2396.txt")
// true

spy

Proxy input and print to console.log. Useful for debugging pipe chains.

spy
Parameters
props (Object)
source (any)
Returns
any:

pipeP

Performs left-to-right function composition. The leftmost function may have any arity, the remaining functions must be unary.

Functions can return a Promise, behaving like Promise.sequence.

pipeP
Parameters
firstFn (Function) First function in chain
restFn (Array<Function>) Remaining bottom functions
input (any) First function arguments
Returns
Promise<any>:
Related
pipe
Example
const inc = input => input + 1
const incP = input => Promise.resolve(input + 1)

pipeP(incP, inc)(2).then(result => {
  // => result = 4
})

clone

Creates a new instance of the object with same properties than original. Will not inherit prototype, only own enumerable properties.

clone
Parameters
input (any) Source input value
Returns
any: New instance of source
Related
deepEqual
Example
let x = {a: [1]}

clone(x)
// => {a: [1]}

close(x) === x
// => false

repeat

Return an array of fixed size containing a specified value or function result

repeat
Parameters
fn ((Function | any)) Function or value to repeat
input (number) Number of times
params (...any) Function params
Returns
Array:
Example
repeat(2)(3)
// => [2, 2, 2]

repeat(index => index + 1, 3)
// => [1, 2, 3]

curry

Partially apply a function

curry
Parameters
fn (Function) The function to apply
params (any) The arguments to apply, in order
Returns
(Function | any): If the number of arguments provided is sufficient to call the function, call the function and return the result. Otherwise, return a new function which takes additional parameters, returning the result of calling curry on the function with the provided parameters.
Example
const sum = (a, b) => a + b

curry(sum)(1)(2) = 3

compact

Returns a copy of the object or array with all null or undefined values removed.

compact
Parameters
input ((Array | Object))
Returns
(Array | Object):
Related
compactMany is
Example
compact([1, null, undefined, {}])
// => [1, {}]

compact({
  a: "Lorem Ipsum",
  b: null,
  c: undefined,
  d: false,
  f: lambda,
 }),
// => {
//  a: "Lorem Ipsum",
//  d: false,
//  f: lambda
// }

cases

Functional case statement.

cases
Parameters
conditions (Array<Function, Function>) List of 2-tuples of functions (if, then)
otherwise (Function = i) Function to call if no condition matches, Defaults to identity.
source (any) Value to check
Returns
any: The result of calling the first matching then function or the otherwise function on the input.
Related
when
Example
cases([
 [x === 0, x => x * 2],
 [x === 1, x => x],
], x => x + 1)(2)
// => 3

_pick

_pick
Parameters
key (string) Field name to extract values from
input (Array<Object>) Array of objects
Returns
Array:

_pluckOne

_pluckOne
Parameters
keys (Array<string>) The properties to be filtered out
input (Object) The source object
Returns
Object:

_pluck

_pluck
Parameters
keys (Array<string>)
input ((Object | Array<Object>))
Returns
(Object | Array<Object>):

values

Get list with names of all own properties

values
Parameters
input ((Array | Object)) Array or Object to extract values from
Returns
Array<string>: List of property names
Example
values(["lorem", "ipsum"])
// => ["lorem", "ipsum"]

values({ foo: "bar", lorem: "ipsum"})
// => ["bar", "ipsum"]

values("foo"), values(12), values(null), etc
// => []

_renameOne

_renameOne
Parameters
mappings (Object)
input (Object)
Returns
Object:

_renameMany

_renameMany
Parameters
mappings (Object)
input ((Object | Array<Object>))
Returns
(Object | Array<Object>):

renameKeys

Rename keys inside an object

renameKeys
Parameters
params (...any)
Returns
(Object | Array<Object>):
Example
rename({ old: "new" }, { old: 42 })
// => { new: 42 }

rename({ old: "new" }, [{ old: 42 }, { old: 41 }])
// => [{ new: 42 }, { new: 41 }]

page

Get a subset array using offset and limit

page
Parameters
$0 (Object = {})
Name Description
$0.offset any (default 0)
$0.limit any (default 10)
props (Object)
Name Description
props.offset number
props.limit number
input (Array)
Returns
Array:
Example
page({
  offset: 1,
  limit: 5
})([1, 2, 3, 4, 5, 6, 7, 8])
// => [2, 3, 4, 5, 6]

push

Add elements at end of array

push
Parameters
elements (any)
input (Array)
Returns
Array:
Example
push(2)([1]) // => [1, 2]
push(2, 4)([1]) // => [1, 2, 4]

max

Find the maximum value in a source array

max
Parameters
input (Array<number>) Array of numbers
Returns
number:
Example
max([-1, 1, 10, 3])
// => 10

const fn = element => (new Date(element.time))
const input = [
  { time: "2018-05-15T11:20:07.754110Z" },
  { time: "2018-06-11T09:01:54.337344Z" },
  { time: "2018-06-08T08:26:12.711071Z" },
]
max(fn, input)
// => {time: "2018-06-11T09:01:54.337344Z"}

min

Find the minimum value in a source array

min
Parameters
input (Array<number>) Array of numbers
Returns
number:
Example
min([-1, 1, 10, 3])
// => -1

const fn = element => ( new Date( element.time ) )
const input = [
  { time: "2018-05-15T11:20:07.754110Z" },
  { time: "2018-06-11T09:01:54.337344Z" },
  { time: "2018-06-08T08:26:12.711071Z" },
]
min(fn)(input)
// => {time: "2018-05-15T11:20:07.754110Z"}

_move

_move
Parameters
from (number)
to (number)
input (Array)
Returns
Array:

move

Move element from one position to another

move
Parameters
params (...any)
Returns
Array:
Example
move(0, 1, [1, 2])
// => [2, 1]

dropLast

Remove elements from end of array

dropLast
Parameters
count (number) Number of element to remove (default 1)
input (Array) Source array
Returns
Array:

append

Add array or element at the end of array

append
Parameters
subset ((any | Array)) Content to add
source (Array) Source array to append to
Returns
Array:
Related
prepend
Example
append([1])([4, 5])
// => [1, 4, 5]

prepend

Add array or element at begining of array

prepend
Parameters
subset ((any | Array)) Content to add
input (Array) Source array to prepend to
Returns
Array:
Example
prepend([1])([4, 5])
// => [1, 4, 5]

toggle

Add element if not exists, remove otherwise

toggle
Parameters
element (any)
source (Array)
Returns
Array:
Example
toggle(1)([1, 2])
// => [2]

toggle(1, [2])
// => [1, 2]

replaceString

Replace substring in string

replaceString
Parameters
oldString (string) The old string
newString (string) The new string
Returns
string:

replaceArray

Replace element in array (shallow equal)

replaceArray
Parameters
oldElm (any)
newElm (any)
Returns
Array:

replace

Replace substring if source is string, replace element (shallow equal) if source is Array

replace
Parameters
oldElm ((string | any))
newElm ((string | any))
source ((string | Array))
Returns
(string | Array):

replaceWith

Replace object element in array using filter object

replaceWith
Parameters
filter (Object) Filter object to match against each element
newValue (Object) Object to replace matching elements
source (Array<Object>)
Returns
Array:
Example
replaceWith(
 {id: 2},
 {id: 2, title: "boss", isBoss: true}
 )([
   {id: 2, title:"minion"}
   {id: 3, title:"minion"}
 ])
// => [
//   {id: 2, title:"boss", isBoss: true},
//   {id: 3, title:"minion"}
// ]

replaceWith({ id: 2 }, item => ({
  ...item,
  content: ["new", "updated", "field"],
}))([
  { id: 1, name: "foo", content: [] },
  { id: 2, name: "bar", content: [] },
])
// [
//   { id: 1, name: "foo", content: [] },
//   { id: 2, name: "bar", content: ["new", "updated", "field"] },
// ],

findIndex

Find the position the first element that satisfies a predicate function

findIndex
Parameters
fn ((Function | Array<Function>)) Predicate applied to each element
source (Array<Object>) Source array to iterate over
Returns
number: Position of found element or -1 if not found
Example
const comments = [{id: 1, body: ""}, {id: 2, body: "dolor"}]

findIndex(item => item.body === "lorem")(comments)
// => -1

findIndex([get("body"), equals("dolor")], null, comments)
// => 1

join

Combine two arrays into one a set (array of unique items), composed of items from both arrays.

The function starts with the distinct items from aList and each item of bList will be searched using a shallow equal. If found, it will be discarded.

join
Parameters
aList (Array<any>)
bList (Array<any>)
Returns
Array<any>:
Related
overlapBy intersect intersectBy
Example
join([1, 1, 2, 3, 3], [3, 3, 4, 4, 5])
// => [1, 2, 3, 4, 5]

intersect

Combine two arrays into one a set (array of unique items), composed of common items from both arrays.

The function starts with an empty array and each item of bList will be searched in aList using a shallow equal. If it's found, it's also checked if it has not been already added.

intersect
Parameters
aList (Array<any>)
bList (Array<any>)
Returns
Array<any>:
Related
intersectBy overlap overlapBy
Example
intersect([1, 2, 3, 3], [3, 3, 4, 5])
// => [3]

intersectBy

Combine two arrays into one a set (array of unique items), composed of common items from both arrays. Allow custom predicate and merge functions.

The function starts with an empty array and each item of bList will be searched in aList using a shallow equal. If it's found, it's also checked if it has not been already added.

intersectBy
Parameters
predicateFn (Function)
mergeFn (Function)
aList (Array<any>)
bList (Array<any>)
Returns
Array<any>:
Related
intersect overlap overlapBy
Example
intersectBy(
  (a, b) => a.id === b.id,
  (a, b) => ({ ...a, ...b }),
  [
    { id: 1, lorem: "ipsum" },
    { id: 2, foo: "bar1" },
    { id: 2, foo: "bar2" },
  ],
  [
    { id: 2, comments: [] },
    { id: 3, comments: [] },
  ]
)
// => [{ id: 2, foo: "bar1", comments: [] }]

dec

Substract one

dec
Parameters
input (number) Input number
Returns
number:
Example
dec(2)
// => 1

inc

Add one

inc
Parameters
input (number) Source input
Returns
number:
Example
inc(2)
// => 3

gt

Grater compare.

gt
Parameters
a (number) First number
b (number) Second number
Returns
boolean:
Example
gt(10)(4)
// => false

gt(10, 14)
// => true

lt

Less compare.

Since this will mostly be used in pipe, the first param in the curry chain is the second operand.

lt
Parameters
second (number) Second number
first (number) First number
Returns
boolean:
Example
lt(10)(4)
// => true

lt(10)(14)
// => false

random

Generate random number between interval

random
Parameters
min (number = 0) Minimum value
max (number = 1) Maximum value
Returns
number:

split

Splits a String object into an array of strings by separating the string into substrings, using a specified separator string to determine where to make each split.

split
Parameters
params (...any)
Name Description
params.separator (string | RegExp) Points where each split should occur
params.input string Input string
Returns
Array:
Example
split(",", "lorem,ipsum")
// ["lorem", "ipsum"]

splitInGroupsOf

Split an array into multiple arrays of set size

splitInGroupsOf
Parameters
params (...any)
Name Description
params.size number
params.source Array
Returns
Array<Array>:
Example
split(2, [1, 2, 3, 4])
// [[1, 2], [3, 4]]

startsWith

Test if string starts with substring

startsWith
Parameters
search ((string | any))
source ((string | array))
Returns
boolean:
Example
startsWith("lorem", "lorem ipsum")
// => true

startsWith("lorem", ["lorem", "ipsum"])
// => true

startsWith("dolor")("lorem ipsum")
// false

endsWith

Test if string ends with substring

endsWith
Parameters
search (string) Search string
source (string) Source string
Returns
boolean:
Example
endWith("ipsum", "lorem ipsum")
// => true

toLower

Convert string to lower case

toLower
Parameters
input (string)
Returns
string:
Related
toUpper
Example
toLower("Lorem Ipsum")
// "lorem ipsum"

toUpper

Convert string to upper case

toUpper
Parameters
input (string)
Returns
string:
Related
toLower
Example
toUpper("Lorem Ipsum")
// "LOREM IPSUM"

trim

Remove char from beginning and end of string

trim
Parameters
params (...any)
char (string) Character to be removed
source (string) Source string
Returns
string:
Example
trim()(" lorem  ")
// => "lorem"

trim("-", "-- lorem  -")
// => " lorem  "

contains

Test if string contains substring

contains
Parameters
search (string) Search string
source (string) Source string
Returns
boolean:
Example
contains("ipsum")("lorem ipsum")
// => true

unite

Unite all elements of an array into a string

unite
Parameters
separator (string) Separator between each adjacent elements
source (Array) Source array
Returns
string:
Example
unite(",", ["lorem", "ipsum"])
// => "lorem,ipsum"

escapeRegExp

Make safe for RegExp'ing

escapeRegExp
Parameters
source (string) Source string
Returns
string:
Example
escapeRegExp( "lorem. ipsum [dolor]" )
// => "lorem \\. ipsum \\[dolor\\]"