Skip to main content

Functions​

arrayFromValue​

▸ arrayFromValue<T>(length): (value: T) => ReadonlyArray<T>

Generate a new array of size length with the provided value

Type parameters​

Name
T

Parameters​

NameTypeDescription
lengthnumberthe length of the array to generate

Returns​

fn

the function to generate the array

▸ (value): ReadonlyArray<T>

Parameters​
NameType
valueT
Returns​

ReadonlyArray<T>

Example

arrayFromValue<string>(5)('a') // ['a', 'a', 'a', 'a', 'a']

Example

chain('a')
.chain(arrayFromValue<string>(5))
.value() // ['a', 'a', 'a', 'a', 'a']

Defined in​

array-from-value/array-from-value.ts:20


castTo​

▸ castTo(mapping): (ob: object) => object

Cast properties of an object or an array of object, given provided mapping

Parameters​

NameTypeDescription
mappingCastMappingMapping between key and caster.

Returns​

fn

The function to apply on the object or the array to do cast its properties into another object or array

▸ (ob): object

Parameters​
NameType
obobject
Returns​

object

Example

castTo(
({ a }) => parseInt(a, 10),
({ b }) => Math.floor(b),
({ c }) => parseInt(c, 16)
)({ a: '1', b: 2.1, c: 'A' }) // { a: 1, b: 2, c: 10 }'`
castTo([
{a: 1, b: 2, c:3},
{a: 4, b: 5, c:6}
])({a: x => x + x, b: x => x}) // [{a: 2, b: 2, c:3}, {a: 8, b: 5, c:6}]

Example

chain({ a: '1', b: 2.1, c: 'A' })
.chain(castTo(
({ a }) => parseInt(a, 10),
({ b }) => Math.floor(b),
({ c }) => parseInt(c, 16)
))
.value() // { a: 1, b: 2, c: 10 }`
chain([
{a: 1, b: 2, c:3},
{a: 4, b: 5, c:6}
])
.chain(castTo({a: x => x + x, b: x => x}))
.value() // [{a: 2, b: 2, c:3}, {a: 8, b: 5, c:6}]

Defined in​

cast-to/cast-to.ts:44


chain​

▸ chain<T>(value): Chain<T>

Enchain any value.

To get the value, apply .value()

Type parameters​

Name
T

Parameters​

NameTypeDescription
valueTthe value to insert at the start of the chain

Returns​

Chain<T>

Defined in​

chain/chain.ts:14


chainFn​

▸ chainFn<T>(f): ChainFn<T>

Enchain any function. To get the value, apply .value() To transform the value with a function f, apply .chain(f)

Type parameters​

Name
T

Parameters​

NameTypeDescription
f(e: any) => Tthe first function to apply in the chain

Returns​

ChainFn<T>

Defined in​

chain-fn/chain-fn.ts:14


countCharacter​

▸ countCharacter(character): (s: string) => number

Count the number of character into the chained string

Parameters​

NameTypeDescription
characterstringthe character to count

Returns​

fn

the number of character's occurence in s

▸ (s): number

Parameters​
NameType
sstring
Returns​

number

Example

countCharacter('a')('abba') // 2

Example

chain('abba')
.chain(countCharacter(2))
.value() // 2

Defined in​

count-character/count-character.ts:20


entries​

▸ entries(): (ob: object) => ReadonlyArray<ReadonlyArray<any>>

It extract keys/values in a new Array Iterator object that contains the key/value pairs for each index in the array.

Returns​

fn

the function to apply on the object to extract key/values

▸ (ob): ReadonlyArray<ReadonlyArray<any>>

Parameters​
NameType
obobject
Returns​

ReadonlyArray<ReadonlyArray<any>>

Example

entries()({ a: 1, b: 2, c: 3 }) // [['a', 1], ['b', 2], ['c', 3]]

Example

chain({ a: 1, b: 2, c: 3 })
.chain(entries())
.value() // [['a', 1], ['b', 2], ['c', 3]]

Defined in​

entries/entries.ts:23


every​

▸ every<T>(iteratee): (array: ReadonlyArray<T>) => boolean

Determines whether all the members of an array satisfy the specified test.

Type parameters​

Name
T

Parameters​

NameTypeDescription
iteratee(value: T, index: number, array: readonly T[]) => booleanA function that accepts up to three arguments.

Returns​

fn

the function to apply on the array to determine if its satisfy the specified test

▸ (array): boolean

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

boolean

Example

every<number>(x => x < 6)([1, 2, 3, 4, 5]) // true

Example

chain([1, 2, 3, 4, 5])
.chain(every<number>(x => x < 6))
.value() // true

Defined in​

every/every.ts:20


filter​

▸ filter<T>(iteratee): (array: ReadonlyArray<T>, links?: Links) => ReadonlyArray<T>

This method filter the elements of the chained array. See the native filter for more informations.

Type parameters​

Name
T

Parameters​

NameTypeDescription
iterateeIteratee<T, boolean>The iteratee invoked per element to decide to keep or not the element.

Returns​

fn

the function to apply on the array to filter it

▸ (array, links?): ReadonlyArray<T>

Parameters​
NameType
arrayReadonlyArray<T>
links?Links
Returns​

ReadonlyArray<T>

Example

filter<number>((x: number) => 0 === x % 2)([1, 2, 3, 4, 5]) // [2, 4]

Example

chain([1, 2, 3, 4, 5])
.chain(filter(x => 0 === x % 2))
.value() // [2, 4]

Defined in​

filter/filter.ts:23


find​

▸ find<T>(predicate): (array: ReadonlyArray<T>) => T | undefined

Returns the value of the first element in the array where predicate is true, and undefined otherwise.

Type parameters​

Name
T

Parameters​

NameTypeDescription
predicate(value: T, index: number, array: readonly T[]) => booleanfind calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined.

Returns​

fn

A find function ready to applied on an array

▸ (array): T | undefined

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

T | undefined

Example

const input = [
{ a: 1, b: 'a' },
{ a: 2, b: 'b' },
{ a: 3, b: 'c' },
{ a: 4, b: 'd' }
];
find<{ a: number; b: string }[]>(({ a }) => 3 === a)(input)
// { a: 3, b: 'c' }

Example

chain(input)
.chain(find<{ a: number; b: string }[]>(({ a }) => 3 === a))
.value() // { a: 3, b: 'c' }

Defined in​

find/find.ts:30


flat​

▸ flat<T>(): (array: ReadonlyArray<ReadonlyArray<T>>) => ReadonlyArray<T>

Flatten an array of array into an array by concat all array items

Type parameters​

Name
T

Returns​

fn

A flat function ready to applied on an array of array

▸ (array): ReadonlyArray<T>

Parameters​
NameType
arrayReadonlyArray<ReadonlyArray<T>>
Returns​

ReadonlyArray<T>

Example

flat<number>()([[1, 2], [3, 4, 5]]) // [1, 2, 3, 4, 5]

Example

chain([[1, 2], [3, 4, 5]])
.chain(flat<number>())
.value() // [1, 2, 3, 4, 5]

Defined in​

flat/flat.ts:18


fromEntries​

▸ fromEntries(): (en: ReadonlyArray<[string, unknown]>) => { [key: string]: unknown; }

Transform an array of key/value pairs into a keys/values object

Returns​

fn

the function to apply on the array to transform it into an object

▸ (en): Object

Parameters​
NameType
enReadonlyArray<[string, unknown]>
Returns​

Object

Example

fromEntries()([['a', 1],['b', 'c']]) // {a: 1, b: 'c'}

Example

chain([['a', 1],['b', 'c']])
.chain(fromEntries())
.value() // {a: 1, b: 'c'}

Defined in​

from-entries/from-entries.ts:19


hash​

▸ hash<T>(): (value: T) => string

Convert the passed value into a string. 2 values that have the same "value" but are referenced with 2 variables will have the same hash.

Type parameters​

Name
T

Returns​

fn

the function to apply on the TBD to do something

▸ (value): string

Parameters​
NameType
valueT
Returns​

string

Example

hash()(1) === hash()(1)
hash()(1) !== hash()("1")
hash()(true) !== hash()("true")

Defined in​

hash/hash.ts:28


▸ head<T>(): (array: ReadonlyArray<T>) => T | undefined

Return the first element of an array and return undefined if the array is empty

Type parameters​

Name
T

Returns​

fn

the function to apply on the array to extract the first element

▸ (array): T | undefined

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

T | undefined

Example

head<number>()([1, 2, 3, 4, 5]) // 1

Example

chain([1, 2, 3, 4, 5])
.chain(head<number>())
.value() // 1

Defined in​

head/head.ts:19


ifElse​

▸ ifElse<T, U, V>(predicat, ifTransform, elseTransform): (value: T) => U | V

Apply ifTransform if predicat is verify, otherwise, apply elseTransform

Type parameters​

Name
T
U
V

Parameters​

NameTypeDescription
predicat(value: T) => booleana function that receive input and return a boolean, if return true, the ifTransform is apply, otherwise, apply elseTransform
ifTransform(value: T) => Ua transform function.
elseTransform(value: T) => Va transform function.

Returns​

fn

the function to apply on whatever to transform

▸ (value): U | V

Parameters​
NameType
valueT
Returns​

U | V

Example

ifElse<number, string, string>(
x => 0 === x % 2,
x => `${x} is even`,
x => `${x} is odd`
)(1) // '1 is odd'

ifElse<number, string, string>(
x => 0 === x % 2,
x => `${x} is even`,
x => `${x} is odd`
)(2) // '2 is even'

Example

chain()
.chain(ifElse<number, string, string>(
x => 0 === x % 2,
x => `${x} is even`,
x => `${x} is odd`
)
.value() // '2 is even'

Defined in​

if-else/if-else.ts:36


isArray​

▸ isArray<T>(value): value is readonly T[]

Determines whether the passed value is an Array

Type parameters​

Name
T

Parameters​

NameTypeDescription
valueanyThe value to test.

Returns​

value is readonly T[]

true if the value is an array, flase otherwise

Example

isArray([1, 2, 3]) // true
isArray(true) // false

Defined in​

is-array/is-array.ts:14


isBoolean​

▸ isBoolean(value): value is boolean

Determines whether the passed value is a boolean

Parameters​

NameTypeDescription
valueanyThe value to test.

Returns​

value is boolean

true if the value is a boolean, flase otherwise

Example

isBoolean(true) // true
isBoolean(false) // true
isBoolean('abba') // false

Defined in​

is-boolean/is-boolean.ts:15


isEmpty​

▸ isEmpty(value): value is Empty

Determines whether the passed value is :

  • undefined or
  • null or
  • is an empty structure

Parameters​

NameTypeDescription
valueanyThe value to test.

Returns​

value is Empty

true if the value is empty, false otherwise

Example

isEmpty(undefined) // true
isEmpty(null) // true
isEmpty([]) // true
isEmpty({}) // true
isEmpty('') // true
isEmpty(0) // false

Defined in​

is-empty/is-empty.ts:29


isEqualObjectOn​

▸ isEqualObjectOn(mapping): (o1: object) => (o1: object) => boolean

Compare 2 objects o1 and o2 on a set of property mapping to determine if they are equals

Parameters​

NameTypeDescription
mappingstring[]a list of key to compare o1 and o2

Returns​

fn

true if o1[key] === o2[key] for all key in mapping, false otherwise

▸ (o1): (o1: object) => boolean

Parameters​
NameType
o1object
Returns​

fn

▸ (o1): boolean

Parameters​
NameType
o1object
Returns​

boolean

Example

isEqualObjectOn(['a', 'b'])({ a: 1, b: 2, c: 3 })({ a: 1, b: 2, c: 4 })
// true
isEqualObjectOn(['a', 'b', 'c'])({ a: 1, b: 2, c: 3 })({ a: 1, b: 2, c: 4 })
// false

Example

chain({ a: 1, b: 2, c: 4 })
.chain(isEqualObjectOn(['a', 'b'])({ a: 1, b: 2, c: 3 }))
.value() // true

Defined in​

is-equal-object-on/is-equal-object-on.ts:27


isNil​

▸ isNil(value): value is undefined | null

Determines whether the passed value is undefined or null.

Parameters​

NameTypeDescription
valueanyThe value to test.

Returns​

value is undefined | null

true if the value is undefined or null, false otherwise

Example

isNil(undefined) // true
isNil(null) // true
isNil([]) // false
isNil({}) // false
isNil('') // false
isNil(0) // false

Defined in​

is-nil/is-nil.ts:21


isNull​

▸ isNull(value): value is null

Determines whether the passed value is null

Parameters​

NameTypeDescription
valueanyThe value to test.

Returns​

value is null

true if the value is null, false otherwise

Example

isNull(null) // true
isNull(undefined) // false
isNull([]) // false
isNull('') // false
isNull(0) // false

Defined in​

is-null/is-null.ts:17


isNumber​

▸ isNumber(value): value is number

Determines whether the passed value is a number

Parameters​

NameTypeDescription
valueanyThe value to test.

Returns​

value is number

true if the value is a number, flase otherwise

Example

isNumber(1) // true
isNumber(true) // false

Defined in​

is-number/is-number.ts:14


isObject​

▸ isObject(value): value is object

Determines whether the passed value is an object

Parameters​

NameTypeDescription
valueanyThe value to test.

Returns​

value is object

true if the value is an object, flase otherwise

Example

isObject({ a: 1 }) // true
isObject({}) // true
isObject([1, 2]) // false
isObject(true) // false

Defined in​

is-object/is-object.ts:16


isString​

▸ isString(value): value is string

Determines whether the passed value is a string

Parameters​

NameTypeDescription
valueanyThe value to test.

Returns​

value is string

true if the value is an string, flase otherwise

Example

isString('abba') // true
isString(true) // false

Defined in​

is-string/is-string.ts:14


isUndefined​

▸ isUndefined(value): value is undefined

Determines whether the passed value is undefined

Parameters​

NameTypeDescription
valueanyThe value to test.

Returns​

value is undefined

true if the value is undefined, false otherwise

Example

isUndefined(undefined) // true
isUndefined(null) // false
isUndefined([]) // false
isUndefined('') // false
isUndefined(0) // false

Defined in​

is-undefined/is-undefined.ts:17


join​

▸ join<T>(separator?): (array: ReadonlyArray<T>) => string

Adds all the elements of an array separated by the specified separator string.

Type parameters​

Name
T

Parameters​

NameTypeDescription
separator?stringA string used to separate one element of an array from the next in the resulting String.

Returns​

fn

the function to apply on the TBD to do something

▸ (array): string

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

string

Example

join()([1, 2, 3, 4, 5]) // 1,2,3,4,5

Example

chain([1, 2, 3, 4, 5])
.chain(join('/'))
.value() // 1/2/3/4/5

Defined in​

join/join.ts:21


keys​

▸ keys(): (ob: Readonly<object>) => string[]

This method extract own enumerable properties of an object into an array See the native Object.keys for more informations.

Returns​

fn

the function to apply on the object to extract its keys

▸ (ob): string[]

Parameters​
NameType
obReadonly<object>
Returns​

string[]

Example

keys()({ a: 1, b: 2, c: 3 }) // ['a', 'b', 'c']

Example

chain({ a: 1, b: 2, c: 3 })
.chain(keys())
.value() // ['a', 'b', 'c']

Defined in​

keys/keys.ts:19


last​

▸ last<T>(): (element: ReadonlyArray<T>) => T | undefined

Return the last element of an array. An empty array has an undefined last element

Type parameters​

Name
T

Returns​

fn

the function to apply on the array to return its last element

▸ (element): T | undefined

Parameters​
NameType
elementReadonlyArray<T>
Returns​

T | undefined

Example

last<number>()([1, 2, 3, 4, 5]) // 5

Example

chain([1, 2, 3, 4, 5])
.chain(last<number>())
.value() // 5

Defined in​

last/last.ts:19


length​

▸ length<T>(): (elements: ReadonlyArray<T>) => number

Get the length of the table

Type parameters​

Name
T

Returns​

fn

the function to apply to get the array length

▸ (elements): number

Parameters​
NameType
elementsReadonlyArray<T>
Returns​

number

Example

length<number>()([0, 1, 2, 3, 4]) // 5

Example

chain([0, 1, 2, 3, 4])
.chain(length<number>())
.value() // 5

Defined in​

length/length.ts:18


loopFor​

▸ loopFor<T>(iteration, iteratee): (input: T) => T

This method loop on an input:

  • at first, output = input
  • on each call, it output = iteratee(output)
  • the loop is parameterize by iteration as a number of loop to apply, or a start, stop, step object
  • finally, returns output

Type parameters​

Name
T

Parameters​

NameTypeDescription
iterationnumber | IterationThe number of iteration, or a start, stop, step object.
iteratee(x: T, index: number) => TThe iteratee invoked per element.

Returns​

fn

the function to apply on the input

▸ (input): T

Parameters​
NameType
inputT
Returns​

T

Example

loopFor<number>(5, x => 1 + x)(1) // 6

Example

loopFor<number>({ start: 2, stop: 10, step: 2 }, (x, i) => x + i ** 2)(0)
// 2² + 4² + 6² + 8² = 120

Example

chain(1)
.chain(loopFor<number>(5, x => 1 + x))
.value() // 6

Defined in​

loop-for/loop-for.ts:50


loopWhile​

▸ loopWhile<T>(predicate, iteratee): (input: T) => T

This method loop on an input:

  • at first, output = input
  • while predicat(output) is true, output = iteratee(output)
  • finally, returns output

Type parameters​

Name
T

Parameters​

NameTypeDescription
predicate(element: T) => booleanThe function apply on each loop to decide to : continue (return true), or to stop (return false)
iteratee(element: T) => TThe iteratee invoked on each loop.

Returns​

fn

the function to apply on the input

▸ (input): T

Parameters​
NameType
inputT
Returns​

T

Example

loopWhile<number>(x => x < 10, x => x ** 2)(2) // 16

Example

chain(2)
.chain(loopWhile<number>(x => x < 10, x => x ** 2))
.value() // 16

Defined in​

loop-while/loop-while.ts:24


map​

▸ map<T, U>(iteratee): (array: ReadonlyArray<T>, links?: Links) => ReadonlyArray<U>

This method creates a new array with the results of calling a provided function on every element in the calling array. See the native map for more informations.

Type parameters​

Name
T
U

Parameters​

NameTypeDescription
iterateeIteratee<T, U>The iteratee invoked per element.

Returns​

fn

the function to apply on the array to transform

▸ (array, links?): ReadonlyArray<U>

Parameters​
NameType
arrayReadonlyArray<T>
links?Links
Returns​

ReadonlyArray<U>

Example

map<number, number>(x => 1 + x))([1, 2, 3, 4, 5]) // [2, 3, 4, 5, 6]

Example

chain([1, 2, 3, 4, 5])
.chain(map<number, number>(x => 1 + x)))
.value() // [2, 3, 4, 5, 6]

Defined in​

map/map.ts:23


max​

▸ max(): (elements: ReadonlyArray<number>) => number

Return the maximum of the list

Returns​

fn

the function to apply on the array to return its maximum

▸ (elements): number

Parameters​
NameType
elementsReadonlyArray<number>
Returns​

number

Example

max()([10, 12, 15, 9]) // 15

Example

chain([10, 12, 15, 9])
.chain(max())
.value() // 15

Defined in​

max/max.ts:18


maxBy​

▸ maxBy<T>(iteratee): (elements: ReadonlyArray<T>) => T | undefined

Return the maximum of the list according the iteratee

Type parameters​

Name
T

Parameters​

NameTypeDescription
iteratee(element: T) => numberThe iteratee invoked per element.

Returns​

fn

the function to apply on the array to return its maximum

▸ (elements): T | undefined

Parameters​
NameType
elementsReadonlyArray<T>
Returns​

T | undefined

Example

maxBy<{ x:number; y:number; }>(e => e.x)([
{ x:1, y:5 },
{ x:2, y:4 },
{ x:3, y:3 },
{ x:4, y:2 }
]) // { x:4, y:2 }
maxBy<{ x:number; y:number; }>(e => e.y)([
{ x:1, y:5 },
{ x:2, y:4 },
{ x:3, y:3 },
{ x:4, y:2 }
]) // { x:1, y:5 }

Example

chain([{ x:1, y:5 }, { x:2, y:4 }, { x:3, y:3 }, { x:4, y:2 }])
.chain(maxBy<{ x:number; y:number; }>(e => e.x))
.value() // { x:4, y:2 }

Defined in​

max-by/max-by.ts:30


min​

▸ min(): (elements: ReadonlyArray<number>) => number

Return the minimum of the list

Returns​

fn

the function to apply on the array to return its minimum

▸ (elements): number

Parameters​
NameType
elementsReadonlyArray<number>
Returns​

number

Example

min()([10, 12, 15, 9]) // 9

Example

chain([10, 12, 15, 9])
.chain(min())
.value() // 9

Defined in​

min/min.ts:18


minBy​

▸ minBy<T>(iteratee): (elements: ReadonlyArray<T>) => T | undefined

Return the minimum of the list according the iteratee

Type parameters​

Name
T

Parameters​

NameTypeDescription
iteratee(element: T) => numberThe iteratee invoked per element.

Returns​

fn

the function to apply on the array to return its minimum

▸ (elements): T | undefined

Parameters​
NameType
elementsReadonlyArray<T>
Returns​

T | undefined

Example

minBy<{ x:number; y:number; }>(e => e.x)([
{ x:1, y:5 },
{ x:2, y:4 },
{ x:3, y:3 },
{ x:4, y:2 }
]) // { x:1, y:5 }
minBy<{ x:number; y:number; }>(e => e.y)([
{ x:1, y:5 },
{ x:2, y:4 },
{ x:3, y:3 },
{ x:4, y:2 }
]) // { x:4, y:2 }

Example

chain([{ x:1, y:5 }, { x:2, y:4 }, { x:3, y:3 }, { x:4, y:2 }])
.chain(minBy<{ x:number; y:number; }>(e => e.x))
.value() // { x:1, y:5 }

Defined in​

min-by/min-by.ts:30


not​

▸ not<T>(predicat): (element: T) => boolean

This method return the negation of the boolean result of the passed function, ie: !predicat(x)

Type parameters​

Name
T

Parameters​

NameTypeDescription
predicat(element: T) => booleanThe function that return a boolean.

Returns​

fn

the function to apply on the input to return the negation

▸ (element): boolean

Parameters​
NameType
elementT
Returns​

boolean

Example

const isEven = x => 0 === x % 2;
const isOdd = not<number>(isEven);
isOdd(1) // true

Example

const isEven = x => 0 === x % 2;
chain([1, 2, 3, 4])
.chain(filter(not(isEven))
.value() // [1, 3]

Defined in​

not/not.ts:23


partition​

▸ partition<T, K>(toKey): (array: ReadonlyArray<T>) => ReadonlyArray<ReadonlyArray<T>>

Partition an array according a sub version of its elements. Each values in the insides arrays are identical according their form reduce by the toKey function. Comparison between 2 elements is perform with an hash of the toKey(element) form.

Type parameters​

Name
T
K

Parameters​

NameTypeDescription
toKey(element: T) => Kthe function to transform array element into something that will be use to partition the array.

Returns​

fn

the function to apply on the array to partition it according to th toKey function

▸ (array): ReadonlyArray<ReadonlyArray<T>>

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

ReadonlyArray<ReadonlyArray<T>>

Example

partition<{ a: number; b: number; }, number>(x => x.a)([
{ a: 1, b: 1 }, { a: 1, b: 2 },
{ a: 2, b: 1 }, { a: 2, b: 2 }
])
// [
[{ a: 1, b: 1 }, { a: 1, b: 2 }],
[{ a: 2, b: 1 }, { a: 2, b: 2 }]
]
partition<number, number>(Math.floor)([1.1, 1.5, 2.1, 2.3, 2.8, 3, 4.12])
// [
[1.1, 1.5],
[2.1, 2.3, 2.8],
[3],
[4.12]
]

Example

chain([{ a: 1, b: 1 }, { a: 1, b: 2 }, { a: 2, b: 1 }, { a: 2, b: 2 }])
.chain(partition<{ a: number; b: number; }, number>(x => x.a))
.value()
// [
[{ a: 1, b: 1}, { a: 1, b: 2 }],
[{ a: 2, b: 1 }, { a: 2, b: 2 }]
]

Defined in​

partition/partition.ts:50


pop​

▸ pop<T>(): (array: ReadonlyArray<T>) => ReadonlyArray<T>

Removes the last element from an array.

Type parameters​

Name
T

Returns​

fn

the function to apply on the array

▸ (array): ReadonlyArray<T>

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

ReadonlyArray<T>

Example

pop<number>()([1, 2, 3, 4, 5]) // [1, 2, 3, 4]

Example

chain([1, 2, 3, 4, 5])
.chain(pop<number>())
.value() // [1, 2, 3, 4]

Defined in​

pop/pop.ts:18


preventNil​

▸ preventNil<S, T>(f): (element: S) => T | undefined

preventNil makes resilient a function to value undefined and null: it prevents to call f with an input undefined or null. If undefined or null are passed, then f is NOT called and undefined is returned.

Type parameters​

Name
S
T

Parameters​

NameTypeDescription
f(x: S) => TThe function to protect.

Returns​

fn

the function to apply on the input to prevent f to have been called

▸ (element): T | undefined

Parameters​
NameType
elementS
Returns​

T | undefined

Example

preventNil<number, number>(x => 1 + x)(undefined) // undefined
preventNil<number, number>(x => 1 + x)(null) // null
preventNil<number, number>(x => 1 + x)(2) // 3

Example

chain([1, 2, 3])
.chain(preventNil(array => array[3]))
.chain(preventNil(x => 1 + x))
.value() // undefined
chain([1, 2, 3])
.chain(preventNil(array => array[1]))
.chain(preventNil(x => 1 + x))
.value() // 3

Example

chain([1, 2, 3])
.chain(preventNil(map(x => x + 1)))
.value() // [2, 3, 4]
chain(undefined)
.chain(preventNil(map(x => x + 1)))
.value() // undefined
chain(null)
.chain(preventNil(map(x => x + 1)))
.value() // undefined

Defined in​

prevent-nil/prevent-nil.ts:50


push​

▸ push<T>(...items): (array: ReadonlyArray<T>) => ReadonlyArray<T>

Return a array with the new elements at the end.

Type parameters​

Name
T

Parameters​

NameTypeDescription
...itemsT[]New elements to add on the Array.

Returns​

fn

the function to apply on the array

▸ (array): ReadonlyArray<T>

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

ReadonlyArray<T>

Example

push<number>(4, 5)([1, 2, 3]) // [1, 2, 3, 4, 5]

Example

chain([1, 2, 3])
.chain(push<number>(4, 5))
.value() // [1, 2, 3, 4, 5]

Defined in​

push/push.ts:19


pushOrReplace​

▸ pushOrReplace<T>(...replace): (array: ReadonlyArray<T>) => ReadonlyArray<T>

Push an element into an array, or replace an existing one if it matchs one.

Type parameters​

Name
T

Parameters​

NameTypeDescription
...replace{ replacement: T ; match: (element: T) => boolean }[]Object with a match function and an element to replace in matching case.

Returns​

fn

the function to apply on the array to do perform the check, replace by the element if matching or push the element if not

▸ (array): ReadonlyArray<T>

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

ReadonlyArray<T>

Example

pushOrReplace<number>({
match: x => x%2 === 0,
replacement: 2
})([4, 6, 8]) // [2, 2, 2]

Example

pushOrReplace<number>({
match: x => x%2 === 0,
replacement: 2
},{
match: x => x%3 === 0,
replacement: 3
})([1, 2, 4]) // [1, 2, 2, 3]

Example

chain([1, 2, 4])
.chain(pushOrReplace<number>({
match: x => x%2 === 0,
replacement: 2
},{
match: x => x%3 === 0,
replacement: 3
}))
.value() // [1, 2, 2, 3]

Defined in​

push-or-replace/push-or-replace.ts:42


reduce​

▸ reduce<T, U>(iteratee, initialValue): (array: ReadonlyArray<T>) => U

Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. See the native reduce for more informations.

Type parameters​

Name
T
U

Parameters​

NameTypeDescription
iteratee(previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => UA function that accepts up to four arguments. The reduce method calls the iteratee function one time for each element in the array.
initialValueUIf initialValue is specified, it is used as the initial value to start the accumulation.

Returns​

fn

A reduce function ready to applied on an array

▸ (array): U

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

U

Example

reduce((a, b) => a - b, 0)([1, 2, 3, 4])
// => ((((0 - 1) - 2) - 3) - 4) = -10
// - -10
// / \ / \
// - 4 -6 4
// / \ / \
// - 3 ==> -3 3
// / \ / \
// - 2 -1 2
// / \ / \
// 0 1 0 1

Example

chain([1, 2, 3, 4])
.chain(reduce((a, b) => a - b, 0))
.value() // -10

Defined in​

reduce/reduce.ts:37

▸ reduce<T>(iteratee): (array: ReadonlyArray<T>) => T

Type parameters​

Name
T

Parameters​

NameType
iteratee(previousValue: T, currentValue: T, currentIndex: number, array: readonly T[]) => T

Returns​

fn

▸ (array): T

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

T

Defined in​

reduce/reduce.ts:47


reverse​

▸ reverse<T>(): (list: string | ReadonlyArray<T>) => string | ReadonlyArray<T>

Reverse a string or an array

Type parameters​

Name
T

Returns​

fn

the function to apply on the string or array to reverse it

▸ (list): string | ReadonlyArray<T>

Parameters​
NameType
liststring | ReadonlyArray<T>
Returns​

string | ReadonlyArray<T>

Example

reverse<number>()([1, 2, 3, 4, 5]) // [5, 4, 3, 2, 1]
reverse()('baba') // 'abab'

Example

chain([1, 2, 3, 4, 5])
.chain(reverse<number>())
.value() // [5, 4, 3, 2, 1]

Defined in​

reverse/reverse.ts:20


shift​

▸ shift<T>(): (array: ReadonlyArray<T>) => ReadonlyArray<T>

Removes the first element from an array.

Type parameters​

Name
T

Returns​

fn

the function to apply on the array

▸ (array): ReadonlyArray<T>

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

ReadonlyArray<T>

Example

shift<number>()([1, 2, 3, 4, 5]) // [1, 2, 3, 4]

Example

chain([1, 2, 3, 4, 5])
.chain(shift<number>())
.value() // [1, 2, 3, 4]

Defined in​

shift/shift.ts:18


some​

▸ some<T>(iteratee): (array: ReadonlyArray<T>) => boolean

Determines whether some of the members of an array satisfy the specified test.

Type parameters​

Name
T

Parameters​

NameTypeDescription
iteratee(value: T, index: number, array: readonly T[]) => booleanA function that accepts up to three arguments.

Returns​

fn

the function to apply on the array to determine if its satisfy the specified test

▸ (array): boolean

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

boolean

Example

some<number>(x => x < 3)([1, 2, 3, 4, 5]) // true

Example

chain([1, 2, 3, 4, 5])
.chain(some<number>(x => x < 3))
.value() // true

Defined in​

some/some.ts:21


sort​

▸ sort<T>(comparator?): (element: ReadonlyArray<T>) => ReadonlyArray<T>

Sort an array with the given comparator function. See the native sort for more informations.

Type parameters​

Name
T

Parameters​

NameTypeDescription
comparator?(d1: T, d2: T) => ComparaisonResultChoiceThe comparator function that defines the sort order. If omitted, the array is sorted according to each character's Unicode code point value, according to the string conversion of each element.

Returns​

fn

the function to apply on the array to sort it.

▸ (element): ReadonlyArray<T>

Parameters​
NameType
elementReadonlyArray<T>
Returns​

ReadonlyArray<T>

Example

sort<number>()([5, 2, 8, 9, 4, 1]) // [1, 2, 4, 5, 8, 9]
sort<string>()(
['a', 'z', 'e', 'r', 't', 'y']
) // ['a', 'e', 'r', 't', 'y', 'z']

Example

sort<{ a: string, b: number }>()([5, 2, 8, 9, 4, 1]) // [1, 2, 4, 5, 8, 9]

Example

chain([5, 2, 8, 9, 4, 1])
.chain(sort<number>())
.value() // [1, 2, 4, 5, 8, 9]

Defined in​

sort/sort.ts:32


sortBy​

▸ sortBy<T>(...f): (array: ReadonlyArray<T>) => ReadonlyArray<T>

Sort an array of object on a given set of field

Type parameters​

Name
T

Parameters​

NameTypeDescription
...f(d: T) => string | number[]one or more function to get string or number from the T element of the array

Returns​

fn

the function to sort the array

▸ (array): ReadonlyArray<T>

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

ReadonlyArray<T>

Example

sortBy<{ a: number; b: number }>(
({ a }) => a, ({ b }) => b
)([
{ a: 2, b: 1 },
{ a: 2, b: 2 },
{ a: 1, b: 2 },
{ a: 1, b: 1 }
])
// [
{ a: 1, b: 1 },
{ a: 1, b: 2 },
{ a: 2, b: 1 },
{ a: 2, b: 2 }
]

Example

chain([
{ a: 2, b: 1 },
{ a: 2, b: 2 },
{ a: 1, b: 2 },
{ a: 1, b: 1 }
])
.chain(sortBy<{ a: number; b: number }>(({ a }) => a, ({ b }) => b))
.value()
// [
{ a: 1, b: 1 },
{ a: 1, b: 2 },
{ a: 2, b: 1 },
{ a: 2, b: 2 }
]

Defined in​

sort-by/sort-by.ts:46


split​

▸ split(separator?): (str: string) => ReadonlyArray<string>

Split a string according a given separator

Parameters​

NameTypeDefault valueDescription
separatorstring''The character to use to split the string.

Returns​

fn

the function to apply on the string to split it

▸ (str): ReadonlyArray<string>

Parameters​
NameType
strstring
Returns​

ReadonlyArray<string>

Example

split('/')('a/b/cd') // ['a', 'b', 'cd']

Example

split('/')('') // []

Example

split('')('abcd') // ['a', 'b', 'c', 'd']

Example

split()('abcd') // ['a', 'b', 'c', 'd']

Example

chain('a/b/cd')
.chain(split('/'))
.value() // ['a', 'b', 'cd']

Defined in​

split/split.ts:31


sum​

▸ sum(): (elements: ReadonlyArray<number>) => number

This method sum all element of the chained array.

Returns​

fn

the function to apply on the array to sum its elements and return the sum

▸ (elements): number

Parameters​
NameType
elementsReadonlyArray<number>
Returns​

number

Example

sum()([1, 2, 3, 4, 5]) // 15

Example

chain([1, 2, 3, 4, 5])
.chain(sum())
.value() // 15

Defined in​

sum/sum.ts:19


sumBy​

▸ sumBy<T>(iteratee): ChainFunction<ReadonlyArray<T>, number>

This method sum all element of the chained array, invoking for each element in array, the iteratee callback to get the value to be summed.

Type parameters​

Name
T

Parameters​

NameTypeDescription
iterateeIteratee<T, number>The iteratee invoked per element to get the value to sum given an element of the array

Returns​

ChainFunction<ReadonlyArray<T>, number>

the function to apply on the array to sum its elements and return the sum

Example

sumBy<number>(x => x)([1, 2, 3, 4]) // 10

Example

sumBy<{ a: number }>(x => x.a)(
[{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }]
) // 10

Example

chain([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }])
.chain(sumBy<{ a: number }>(x => x.a))
.value() // 10

Defined in​

sum-by/sum-by.ts:30


tail​

▸ tail<T>(): (array: ReadonlyArray<T>) => ReadonlyArray<T>

Return the array without the first element. Return an empty array if the input is an empty array.

Type parameters​

Name
T

Returns​

fn

the function to apply on the array to do return it without the first element

▸ (array): ReadonlyArray<T>

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

ReadonlyArray<T>

Example

tail<number>()([1, 2, 3, 4, 5]) // [2, 3, 4, 5]

Example

chain([1, 2, 3, 4, 5])
.chain(tail<number>())
.value() // [2, 3, 4, 5]

Defined in​

tail/tail.ts:20


take​

▸ take<T>(n): (list: string | ReadonlyArray<T>) => string | ReadonlyArray<T>

Extract n first elements of an array

Type parameters​

Name
T

Parameters​

NameTypeDescription
nnumberThe number of elements to extract first

Returns​

fn

the function to apply on the array to extract its n first element

▸ (list): string | ReadonlyArray<T>

Parameters​
NameType
liststring | ReadonlyArray<T>
Returns​

string | ReadonlyArray<T>

Example

take<number>(2)([1, 2, 3, 4, 5]) // [1, 2]
take(2)('abba') // 'ab'

Example

chain([1, 2, 3, 4, 5])
.chain(take<number>(2))
.value() // [1, 2]

Defined in​

take/take.ts:22


toObject​

▸ toObject<T, U>(keyGetter, valueGetter): (array: ReadonlyArray<T>) => { [key: string]: U; }

Convert an array to an associative map store in a javascript object.

Type parameters​

Name
T
U

Parameters​

NameTypeDescription
keyGetter(x: T) => stringA function to extract the key of the association.
valueGetter(x: T) => UA function to extract the value of the association.

Returns​

fn

the function to apply on the array to do convert it into a javascript object

▸ (array): Object

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

Object

Example

toObject<(string | number)[][]>(
item => item[0], item => item[1])([['a', 1], ['b', 'c']]
) // {a: 1, b: 'c'}

Example

chain([['a', 1], ['b', 'c']])
.chain(toObject<(string | number)[][]>(item => item[0], item => item[1]))
.value() // {a: 1, b: 'c'}

Defined in​

to-object/to-object.ts:23


triangular​

▸ triangular<T>(): (array: ReadonlyArray<T>) => ReadonlyArray<ReadonlyArray<T>>

Transform an array in a triangular array [A, B, C, D] => [ [A], [A, B], [A, B, C], [A, B, C, D] ]

Type parameters​

Name
T

Returns​

fn

the function to apply on the array to do transform it to a triangular array

▸ (array): ReadonlyArray<ReadonlyArray<T>>

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

ReadonlyArray<ReadonlyArray<T>>

Example

triangular<number>()([1, 2, 3]) // [[1], [1, 2], [1, 2, 3]]

Example

chain([1, 2, 3])
.chain(triangular<number>())
.value() // [[1], [1, 2], [1, 2, 3]]

Defined in​

triangular/triangular.ts:26


typeOf​

▸ typeOf(element): string

Get an enhanced type of the input. Use toString to compute a more specific "type" than the native typof operator.

Parameters​

NameType
elementunknown

Returns​

string

the enhanced type of the input. Could be:

  • undefined
  • null
  • number
  • boolean
  • string
  • object
  • array
  • function
  • symbol
  • regexp
  • date
  • map
  • weakmap
  • set
  • weakset
  • promise
  • bigint64array
  • int16array
  • int32array
  • int8array
  • int8array
  • uint8array
  • uint8clampedarray
  • int16array
  • uint16array
  • int32array
  • uint32array
  • float32array
  • float64array
  • bigint64array
  • biguint64array
  • arraybuffer
  • sharedarraybuffer
  • math
  • json
  • atomics
  • error

Example

typeOf(undefined); // undefined
typeOf(null); // null
typeOf(NaN); // number
typeOf(5); // number
typeOf({}); // object
typeOf([]); // array
typeOf(''); // string
typeOf(function () {}); // function
typeOf(/a/) // regexp
typeOf(new Date()) // date
typeOf(new WeakMap()) // weakmap
typeOf(new Map()) // map

Defined in​

type-of/type-of.ts:63


uniq​

▸ uniq<T>(comparison?): (element: T[]) => T[]

Returns a new list containing only one copy of each element in the original list, based upon the value returned by applying the supplied function to each list element. Prefers the first item if the supplied function produces the same value on two items. === is used for comparison.

Type parameters​

Name
T

Parameters​

NameTypeDescription
comparison(x: T) => unknownThe comparison method, default set to identity.

Returns​

fn

the function to apply on the array to uniq its elements

▸ (element): T[]

Parameters​
NameType
elementT[]
Returns​

T[]

Example

uniq<number>()([1, 2, 3, 2, 3, 5, 1]) // [1, 2, 3, 5]
uniq<{ a: number; b: number; c: string; }>(({ a, b, c }) => ({ a, b }))([
{ a: 1, b: 1, c: 'a' },
{ a: 1, b: 2, c: 'a' },
{ a: 1, b: 1, c: 'b' }
])) // [{ a: 1, b: 1, c: 'a' }, { a: 1, b: 2, c: 'a' }]

Example

chain([
{ a: 1, b: 1, c: 'a' },
{ a: 1, b: 2, c: 'a' },
{ a: 1, b: 1, c: 'b' }
])
.chain(uniq<{ a: number; b: number; c: string; }>(
({ a, b, c }) => ({ a, b }))
)
.value() // [{ a: 1, b: 1, c: 'a' }, { a: 1, b: 2, c: 'a' }]

Defined in​

uniq/uniq.ts:39


unless​

▸ unless<T, U>(predicat, transform): (value: T) => T | U

Apply transform unless the predicat is verify.

Type parameters​

Name
T
U

Parameters​

NameTypeDescription
predicat(value: T) => booleana function that receive input and return a boolean, if return true, the transform is NOT apply, otherwise, apply transform
transform(value: T) => Ua transform function.

Returns​

fn

the function to apply on whatever to transform or not to transform

▸ (value): T | U

Parameters​
NameType
valueT
Returns​

T | U

Example

unless<number, string>(n => 0 === n % 2, n => `${n} is odd`)(1) // '1 is odd'
unless<number, string>(n => 0 === n % 2, n => `${n} is odd`)(2) // 2

Example

chain(1)
.chain(unless<number, string>(n => 0 === n % 2, n => `${n} is odd`))
.value() // '1 is odd'

Defined in​

unless/unless.ts:22


unshift​

▸ unshift<T>(...items): (array: ReadonlyArray<T>) => ReadonlyArray<T>

Return a array with the new elements at the beginning.

Type parameters​

Name
T

Parameters​

NameTypeDescription
...itemsT[]New elements to add on the Array.

Returns​

fn

the function to apply on the array

▸ (array): ReadonlyArray<T>

Parameters​
NameType
arrayReadonlyArray<T>
Returns​

ReadonlyArray<T>

Example

unshift<number>(4, 5)([1, 2, 3]) // [4, 5, 1, 2, 3]

Example

chain([1, 2, 3])
.chain(unshift<number>(4, 5))
.value() // [4, 5, 1, 2, 3]

Defined in​

unshift/unshift.ts:19


values​

▸ values(): (ob: object) => ReadonlyArray<any>

This method extract own enumerable values of an object into an array See the native Object.values for more informations.

Returns​

fn

the function to apply on the object to extract its values

▸ (ob): ReadonlyArray<any>

Parameters​
NameType
obobject
Returns​

ReadonlyArray<any>

Example

values()({ a: 1, b: 2, c: 3 }) // [1, 2, 3]

Example

chain({ a: 1, b: 2, c: 3 })
.chain(values())
.value() // [1, 2, 3]

Defined in​

values/values.ts:24