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
Name | Type | Description |
---|---|---|
length | number | the length of the array to generate |
Returns
fn
the function to generate the array
▸ (value
): ReadonlyArray
<T
>
Parameters
Name | Type |
---|---|
value | T |
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
Name | Type | Description |
---|---|---|
mapping | CastMapping | Mapping 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
Name | Type |
---|---|
ob | object |
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
chain
▸ chain<T
>(value
): Chain
<T
>
Enchain any value.
To get the value, apply .value()
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
value | T | the value to insert at the start of the chain |
Returns
Chain
<T
>
Defined in
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
Name | Type | Description |
---|---|---|
f | (e : any ) => T | the first function to apply in the chain |
Returns
ChainFn
<T
>
Defined in
countCharacter
▸ countCharacter(character
): (s
: string
) => number
Count the number of character into the chained string
Parameters
Name | Type | Description |
---|---|---|
character | string | the character to count |
Returns
fn
the number of character's occurence in s
▸ (s
): number
Parameters
Name | Type |
---|---|
s | string |
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
Name | Type |
---|---|
ob | object |
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
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
Name | Type | Description |
---|---|---|
iteratee | (value : T , index : number , array : readonly T []) => boolean | A 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
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type | Description |
---|---|---|
iteratee | Iteratee <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
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type | Description |
---|---|---|
predicate | (value : T , index : number , array : readonly T []) => boolean | find 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
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type |
---|---|
en | ReadonlyArray <[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
Name | Type |
---|---|
value | T |
Returns
string
Example
hash()(1) === hash()(1)
hash()(1) !== hash()("1")
hash()(true) !== hash()("true")
Defined in
head
▸ 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
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type | Description |
---|---|---|
predicat | (value : T ) => boolean | a function that receive input and return a boolean, if return true, the ifTransform is apply, otherwise, apply elseTransform |
ifTransform | (value : T ) => U | a transform function. |
elseTransform | (value : T ) => V | a transform function. |
Returns
fn
the function to apply on whatever to transform
▸ (value
): U
| V
Parameters
Name | Type |
---|---|
value | T |
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
isArray
▸ isArray<T
>(value
): value is readonly T[]
Determines whether the passed value is an Array
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
value | any | The 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
isBoolean
▸ isBoolean(value
): value is boolean
Determines whether the passed value is a boolean
Parameters
Name | Type | Description |
---|---|---|
value | any | The 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
isEmpty
▸ isEmpty(value
): value is Empty
Determines whether the passed value is :
- undefined or
- null or
- is an empty structure
Parameters
Name | Type | Description |
---|---|---|
value | any | The 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
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
Name | Type | Description |
---|---|---|
mapping | string [] | 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
Name | Type |
---|---|
o1 | object |
Returns
fn
▸ (o1
): boolean
Parameters
Name | Type |
---|---|
o1 | object |
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
Name | Type | Description |
---|---|---|
value | any | The 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
isNull
▸ isNull(value
): value is null
Determines whether the passed value is null
Parameters
Name | Type | Description |
---|---|---|
value | any | The 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
isNumber
▸ isNumber(value
): value is number
Determines whether the passed value is a number
Parameters
Name | Type | Description |
---|---|---|
value | any | The 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
isObject
▸ isObject(value
): value is object
Determines whether the passed value is an object
Parameters
Name | Type | Description |
---|---|---|
value | any | The 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
isString
▸ isString(value
): value is string
Determines whether the passed value is a string
Parameters
Name | Type | Description |
---|---|---|
value | any | The 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
isUndefined
▸ isUndefined(value
): value is undefined
Determines whether the passed value is undefined
Parameters
Name | Type | Description |
---|---|---|
value | any | The 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
Name | Type | Description |
---|---|---|
separator? | string | A 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
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type |
---|---|
ob | Readonly <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
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
Name | Type |
---|---|
element | ReadonlyArray <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
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
Name | Type |
---|---|
elements | ReadonlyArray <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
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
Name | Type | Description |
---|---|---|
iteration | number | Iteration | The number of iteration, or a start, stop, step object. |
iteratee | (x : T , index : number ) => T | The iteratee invoked per element. |
Returns
fn
the function to apply on the input
▸ (input
): T
Parameters
Name | Type |
---|---|
input | T |
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
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
Name | Type | Description |
---|---|---|
predicate | (element : T ) => boolean | The function apply on each loop to decide to : continue (return true), or to stop (return false) |
iteratee | (element : T ) => T | The iteratee invoked on each loop. |
Returns
fn
the function to apply on the input
▸ (input
): T
Parameters
Name | Type |
---|---|
input | T |
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
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
Name | Type | Description |
---|---|---|
iteratee | Iteratee <T , U > | The iteratee invoked per element. |
Returns
fn
the function to apply on the array to transform
▸ (array
, links?
): ReadonlyArray
<U
>
Parameters
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type |
---|---|
elements | ReadonlyArray <number > |
Returns
number
Example
max()([10, 12, 15, 9]) // 15
Example
chain([10, 12, 15, 9])
.chain(max())
.value() // 15
Defined in
maxBy
▸ maxBy<T
>(iteratee
): (elements
: ReadonlyArray
<T
>) => T
| undefined
Return the maximum of the list according the iteratee
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
iteratee | (element : T ) => number | The iteratee invoked per element. |
Returns
fn
the function to apply on the array to return its maximum
▸ (elements
): T
| undefined
Parameters
Name | Type |
---|---|
elements | ReadonlyArray <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
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
Name | Type |
---|---|
elements | ReadonlyArray <number > |
Returns
number
Example
min()([10, 12, 15, 9]) // 9
Example
chain([10, 12, 15, 9])
.chain(min())
.value() // 9
Defined in
minBy
▸ minBy<T
>(iteratee
): (elements
: ReadonlyArray
<T
>) => T
| undefined
Return the minimum of the list according the iteratee
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
iteratee | (element : T ) => number | The iteratee invoked per element. |
Returns
fn
the function to apply on the array to return its minimum
▸ (elements
): T
| undefined
Parameters
Name | Type |
---|---|
elements | ReadonlyArray <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
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
Name | Type | Description |
---|---|---|
predicat | (element : T ) => boolean | The function that return a boolean. |
Returns
fn
the function to apply on the input to return the negation
▸ (element
): boolean
Parameters
Name | Type |
---|---|
element | T |
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
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
Name | Type | Description |
---|---|---|
toKey | (element : T ) => K | the 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
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type | Description |
---|---|---|
f | (x : S ) => T | The function to protect. |
Returns
fn
the function to apply on the input to prevent f to have been called
▸ (element
): T
| undefined
Parameters
Name | Type |
---|---|
element | S |
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
push
▸ push<T
>(...items
): (array
: ReadonlyArray
<T
>) => ReadonlyArray
<T
>
Return a array with the new elements at the end.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
...items | T [] | New elements to add on the Array. |
Returns
fn
the function to apply on the array
▸ (array
): ReadonlyArray
<T
>
Parameters
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type | Description |
---|---|---|
...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
Name | Type |
---|---|
array | ReadonlyArray <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
Name | Type | Description |
---|---|---|
iteratee | (previousValue : U , currentValue : T , currentIndex : number , array : readonly T []) => U | A function that accepts up to four arguments. The reduce method calls the iteratee function one time for each element in the array. |
initialValue | U | If 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
Name | Type |
---|---|
array | ReadonlyArray <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<T
>(iteratee
): (array
: ReadonlyArray
<T
>) => T
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
iteratee | (previousValue : T , currentValue : T , currentIndex : number , array : readonly T []) => T |
Returns
fn
▸ (array
): T
Parameters
Name | Type |
---|---|
array | ReadonlyArray <T > |
Returns
T
Defined in
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
Name | Type |
---|---|
list | string | 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
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
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type | Description |
---|---|---|
iteratee | (value : T , index : number , array : readonly T []) => boolean | A 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
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type | Description |
---|---|---|
comparator? | (d1 : T , d2 : T ) => ComparaisonResultChoice | The 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
Name | Type |
---|---|
element | ReadonlyArray <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
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
Name | Type | Description |
---|---|---|
...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
Name | Type |
---|---|
array | ReadonlyArray <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
split
▸ split(separator?
): (str
: string
) => ReadonlyArray
<string
>
Split a string according a given separator
Parameters
Name | Type | Default value | Description |
---|---|---|---|
separator | string | '' | The character to use to split the string. |
Returns
fn
the function to apply on the string to split it
▸ (str
): ReadonlyArray
<string
>
Parameters
Name | Type |
---|---|
str | string |
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
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
Name | Type |
---|---|
elements | ReadonlyArray <number > |
Returns
number
Example
sum()([1, 2, 3, 4, 5]) // 15
Example
chain([1, 2, 3, 4, 5])
.chain(sum())
.value() // 15
Defined in
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
Name | Type | Description |
---|---|---|
iteratee | Iteratee <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
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
Name | Type |
---|---|
array | ReadonlyArray <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
take
▸ take<T
>(n
): (list
: string
| ReadonlyArray
<T
>) => string
| ReadonlyArray
<T
>
Extract n first elements of an array
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
n | number | The 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
Name | Type |
---|---|
list | string | 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
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
Name | Type | Description |
---|---|---|
keyGetter | (x : T ) => string | A function to extract the key of the association. |
valueGetter | (x : T ) => U | A 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
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type |
---|---|
element | unknown |
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
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
Name | Type | Description |
---|---|---|
comparison | (x : T ) => unknown | The comparison method, default set to identity. |
Returns
fn
the function to apply on the array to uniq its elements
▸ (element
): T
[]
Parameters
Name | Type |
---|---|
element | T [] |
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
unless
▸ unless<T
, U
>(predicat
, transform
): (value
: T
) => T
| U
Apply transform
unless the predicat
is verify.
Type parameters
Name |
---|
T |
U |
Parameters
Name | Type | Description |
---|---|---|
predicat | (value : T ) => boolean | a function that receive input and return a boolean, if return true, the transform is NOT apply, otherwise, apply transform |
transform | (value : T ) => U | a transform function. |
Returns
fn
the function to apply on whatever to transform or not to transform
▸ (value
): T
| U
Parameters
Name | Type |
---|---|
value | T |
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
unshift
▸ unshift<T
>(...items
): (array
: ReadonlyArray
<T
>) => ReadonlyArray
<T
>
Return a array with the new elements at the beginning.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
...items | T [] | New elements to add on the Array. |
Returns
fn
the function to apply on the array
▸ (array
): ReadonlyArray
<T
>
Parameters
Name | Type |
---|---|
array | ReadonlyArray <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
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
Name | Type |
---|---|
ob | object |
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]