Functions
These are the available library functions.
identity
A function that takes a single parameter and returns it. Essentially a no-op for mapping.
map(identity, [1, 2, 3])type or = <Args extends any[]>(
...options: Array<(...args: Args) => unknown>
) => (...args: Args): booleanor
Given several methods which can return a boolean, create a new predicate which logically "ors" them together.
const isNotATeen = or(lessThan(13), greaterThan(19))
isNotATeen(13)type or = <Args extends any[]>(
...options: Array<(...args: Args) => unknown>
) => (...args: Args): booleanand
Given several methods which can return a boolean, create a new predicate which logically "ands" them together.
const isBetweenFiveAndTen = and(greaterThan(5), lessThan(10))
isBetweenFiveAndTen(7)type and = <Args extends any[]>(
...options: Array<(...args: Args) => unknown>
) => (...args: Args): booleanapply
Given a function that takes multiple parameters, create a new function which takes those parameters as a single tuple instead.
map
Exactly like Array.prototype.map, but functional instead of on the Array prototype.
chain
Given a value and a function, run the function on the value. This is like map, but for working on any data type. Useful in piped series of computations.
constant
Given a value, return a function that will return that value every time it is called.
cond
Basically a functional switch statement. Run several predicates to find the correct code path, then transform the data as requested.
equals
Given a value, create a new function which will take a second value and compare their equality. Uses Javascript's === operator.
first
Given an array, return the first value or undefined.
nth
Given an array, return the nth value or undefined. nth is 1-indexed.
index
Given an array, return the index value or undefined. index is 0-indexed.
last
Given an array, return the last value or undefined.
rest
Given an array, return every item except the first.
greaterThan
Create a predicate which checks whether a value is greater than a number.
greaterThanEquals
Create a predicate which checks whether a value is greater than or equal a number.
lessThan
Create a predicate which checks whether a value is less than a number.
lessThanEquals
Create a predicate which checks whether a value is less than or equal a number.
isBetween
Create a predicate which checks whether a value is between two values.
pluck
Create a function which grabs a key from an object.
omit
Create a function which removes a key from an object.
pipe
Create a function runs a series of functions in order, passing the result of each step to the next in the series.
Last updated
Was this helpful?