Ƭ T<A
>: A
[]
Represents an array of elements A
Example
import { Arr } from 'tiinvo'
let foo: Arr.T<string> = ['hello']
Since
4.0.0
Name | Type | Description |
---|---|---|
A |
unknown |
the array’s elements’ type |
Ƭ Reducer<A
, B
>: (p
: B
, c
: A
) => B
(p
: B
, c
: A
, i
: number
) => B
(p
: B
, c
: A
, i
: number
, t
: T
<A
>) => B
Name | Description |
---|---|
A |
the reduced value type |
B |
the array type |
▸ (p
, c
): B
Example
import { Arr } from 'tiinvo';
let r: Arr.Reducer<string, number> = (a, b) => a + b.length;
['hello', 'world'].reduce(r, 0) // 10
Name | Type | Description |
---|---|---|
p |
B |
the accumulated value |
c |
A |
the current value |
B
▸ (p
, c
, i
): B
Example
import { Arr } from 'tiinvo';
let r: Arr.Reducer<string, number> = (a, b, i) => a + b.length + i;
['hello', 'world'].reduce(r, 0) // 11
Name | Type | Description |
---|---|---|
p |
B |
the accumulated value |
c |
A |
the current value |
i |
number |
the current index |
B
▸ (p
, c
, i
, t
): B
Example
import { Arr } from 'tiinvo';
let r: Arr.Reducer<string, number> = (a, b, i, t) => a + b.length + i + t.length;
['hello', 'world'].reduce(r, 0) // 13
Name | Type | Description |
---|---|---|
p |
B |
the accumulated value |
c |
A |
the current value |
i |
number |
the current index |
t |
T <A > |
the original array T<A> |
B
▸ get<A
>(a
, i
): T
<A
>
Returns the element Result.t<a>
at index i
of an array T<A>
.
If the index i
is out of range, a Err
will be returned.
import { Arr } 'tiinvo';
Arr.get([10, 20], 1) // 20
Arr.get([10, 20], 3) // Error("Index out of bounds 3 for length 2")
Since
4.0.0
Name | Description |
---|---|
A |
the type of the array A elements |
Name | Type | Description |
---|---|---|
a |
T <A > |
is the array to search |
i |
number |
is the element index |
T
<A
>
▸ get<A
>(a
): Unary
<T
<A
>, T
<A
>>
Returns a Fn.Unary<t<a>, Result.t<a>>
to get the element Result.t<a>
at index i
of an array T<A>
.
If the index i
is out of range, a Err
will be returned.
import { Arr } 'tiinvo';
Arr.get(1)([10, 20]) // 20
Arr.get(3)([10, 20]) // Error("Index out of bounds 3 for length 2")
Since
4.0.0
Name | Description |
---|---|
A |
the type of the array A elements |
Name | Type | Description |
---|---|---|
a |
number |
is the element index |
the unary function
▸ getOr<A
>(a
, b
, i
): A
Returns the element Option.T<A>
at index i
of an array T<A>
.
Example
import { Arr } from 'tiinvo';
Arr.getOr([10, 20], 0, 1) // 20
Arr.getOr([10, 20], 0, 3) // 0
Since
4.0.0
Name | Description |
---|---|
A |
the type of the array A elements |
Name | Type | Description |
---|---|---|
a |
T <A > |
is the array to search |
b |
A |
is the default value |
i |
number |
is the element index |
A
▸ getOr<A
>(a
): Binary
<T
<A
>, number
, A
>
Returns a Fn.Binary<T<A>, number, A>
to get the element Option.T<A>
at index i
of an array T<A>
.
Example
import { Arr } from 'tiinvo';
Arr.getOr(0)([10, 20]) // 20
Arr.getOr(0)([10, 20]) // 0
Since
4.0.0
Name | Description |
---|---|
A |
the type of the array A elements |
Name | Type | Description |
---|---|---|
a |
A |
is the default value |
the binary function
▸ first<A
>(t
): T
<A
>
Returns the first element of an array A
. If the array is empty, returns Option.None
.
Example
import { Arr } 'tiinvo';
Arr.first(['a', 'b']) // 'a';
Arr.first([]) // null;
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type | Description |
---|---|---|
t |
T <A > |
the array |
T
<A
>
Option.Some<A>
if someOption.None
otherwise▸ firstOr<A
>(t
, b
): A
Returns the first element of an array A
or b
if the array is empty.
Example
import { Arr } from 'tiinvo';
Arr.firstOr([10, 20], 0) // 10
Arr.firstOr([], 0) // 0
Since
4.0.0
Name | Description |
---|---|
A |
the inferred type from argument t |
Name | Type | Description |
---|---|---|
t |
T <A > |
the array |
b |
A |
the fallback value |
A
the first element of the array or b
as fallback
▸ firstOr<A
>(t
): Unary
<T
<A
>, A
>
Returns a unary function which gets an array’s first element or returns the fallback t
.
Example
import { Arr } from 'tiinvo';
const firstOr0 = Arr.firstOr(0);
firstOr0([10, 20]) // 10
firstOr0([]) // 0
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type | Description |
---|---|---|
t |
A |
the fallback value |
the unary function
▸ last<A
>(t
): T
<A
>
Returns the last element of an array A
.
Example
import { Arr } 'tiinvo';
Arr.last(['a', 'b']) // 'b';
Arr.last([]) // null;
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type | Description |
---|---|---|
t |
T <A > |
the array |
T
<A
>
Option.Some<A>
if has a last elementOption.None
otherwise▸ lastOr<A
>(t
, b
): A
Returns the last element of an array A
or the fallback b
if the array is empty.
Example
import { Arr } from 'tiinvo';
Arr.lastOr([10, 20], 0) // 20
Arr.lastOr([], 0) // 0
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type | Description |
---|---|---|
t |
T <A > |
the array |
b |
A |
the fallback |
A
The last element of the array t
or b
if t
is empty.
▸ lastOr<A
>(t
): Unary
<T
<A
>, A
>
After setting the fallback value t
, returns a Unary<t<a>, a>
function.
If the array has a length greater than 0, it will return it’s last element, otherwise it will return the fallback t
Example
import { Arr } from 'tiinvo';
Arr.lastOr(0)([10, 20]) // 20
Arr.lastOr(0)([]) // 0
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type | Description |
---|---|---|
t |
A |
the index |
the unary function
▸ guard(x
): x is T<unknown>
Returns true if a
is an array.
import { Arr } from 'tiinvo';
Arr.guard([]) // true
Arr.guard(null) // false
Arr.guard(undefined) // false
Arr.guard(0) // false
Arr.guard('') // false
Since
4.0.0
Name | Type | Description |
---|---|---|
x |
unknown |
the value to check |
x is T<unknown>
▸ guardOf<A
>(g
, x
): x is T<A>
Returns true if b
is an array of a
.
Example
import { Arr, Str } from 'tiinvo';
Arr.guardOf(Str.guard, []) // true
Arr.guardOf(Str.guard, ['a']) // true
Arr.guardOf(Str.guard, ['a', 'b']) // true
Arr.guardOf(Str.guard, ['a', 'b', 'c']) // true
Arr.guardOf(Str.guard, ['a', 'b', 'c', 1]) // false
@template A array’s type @param g the Guard to match @param x the value to match @returns
A
Name |
---|
A |
Name | Type |
---|---|
g |
Guardable <A > |
x |
unknown |
x is T<A>
▸ guardOf<A
>(g
): (x
: unknown
) => x is T<A>
Returns a Functors.Guardable<t<a>>
which returns true if x
is of type T<A>
import { Arr, Str } from 'tiinvo';
const isStrArr = Arr.guardOf(Str.guard);
isStrArr([]) // true
isStrArr(['a']) // true
isStrArr(['a', 'b']) // true
isStrArr(['a', 'b', 'c']) // true
isStrArr(['a', 'b', 'c', 1]) // false
Since
4.0.0
Name |
---|
A |
Name | Type | Description |
---|---|---|
g |
Guardable <A > |
The functor |
fn
the new guard to check if x
is an array of A
▸ (x
): x is T<A>
Name | Type |
---|---|
x |
unknown |
x is T<A>
▸ cmp<A
>(cmp
, a
, b
): ComparableResult
Compares two arrays T<A>
with a given Comparable<A>
.
Example
import { Arr, Str } from 'tiinvo';
Arr.cmp(Str.cmp, ['a'], ['a']) // 0
Arr.cmp(Str.cmp, ['a'], ['b']) // -1
Arr.cmp(Str.cmp, ['b'], ['a']) // 1
Arr.cmp(Str.cmp, ['a'], ['a', 'b']) // -1
Arr.cmp(Str.cmp, ['a', 'b'], ['a']) // 1
Arr.cmp(Str.cmp, ['a', 'b'], ['a', 'b']) // 0
Arr.cmp(Str.cmp, ['a', 'b', 'c'], ['a', 'b']) // 1
Arr.cmp(Str.cmp, ['a', 'b', 'c'], ['a', 'b', 'c']) // 0
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type | Description |
---|---|---|
cmp |
Comparable <A > |
the comparator |
a |
T <A > |
the first array to compare |
b |
T <A > |
the second array to compare |
a
is greater then b
a
is less than b
a
and b
are equal▸ cmp<A
>(cmp
, a
, b
): ComparableResult
Compares two arrays T<A>
with a given ComparableModule<A>
.
Example
import { Arr, Str } from 'tiinvo';
Arr.cmp(Str, ['a'], ['a']) // 0
Arr.cmp(Str, ['a'], ['b']) // -1
Arr.cmp(Str, ['b'], ['a']) // 1
Arr.cmp(Str, ['a'], ['a', 'b']) // -1
Arr.cmp(Str, ['a', 'b'], ['a']) // 1
Arr.cmp(Str, ['a', 'b'], ['a', 'b']) // 0
Arr.cmp(Str, ['a', 'b', 'c'], ['a', 'b']) // 1
Arr.cmp(Str, ['a', 'b', 'c'], ['a', 'b', 'c']) // 0
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type | Description |
---|---|---|
cmp |
ComparableModule <A > |
the comparator module |
a |
T <A > |
the first array to compare |
b |
T <A > |
the second array to compare |
a
is greater then b
a
is less than b
a
and b
are equal▸ cmp<A
>(cmp
, a
): (b
: T
<A
>) => ComparableResult
Compares two arrays T<A>
with a given Comparable<a>
.
Example
import { Arr, Str } from 'tiinvo';
Arr.cmp(Str.cmp, ['a'])(['a']) // 0
Arr.cmp(Str.cmp, ['a'])(['b']) // -1
Arr.cmp(Str.cmp, ['b'])(['a']) // 1
Arr.cmp(Str.cmp, ['a'])(['a', 'b']) // -1
Arr.cmp(Str.cmp, ['a', 'b'])(['a']) // 1
Arr.cmp(Str.cmp, ['a', 'b'])(['a', 'b']) // 0
Arr.cmp(Str.cmp, ['a', 'b', 'c'])(['a', 'b']) // 1
Arr.cmp(Str.cmp, ['a', 'b', 'c'])(['a', 'b', 'c']) // 0
Since
4.0.0
Name |
---|
A |
Name | Type | Description |
---|---|---|
cmp |
Comparable <A > |
the comparator |
a |
T <A > |
the first array to compare |
fn
the unary function which returns
b
is greater then a
b
is less than a
a
and b
are equal▸ (b
): ComparableResult
Name | Type |
---|---|
b |
T <A > |
▸ cmp<A
>(cmp
, a
): (b
: T
<A
>) => ComparableResult
Compares two arrays T<A>
with a given ComparableModule<A>
.
Example
import { Arr, Str } from 'tiinvo';
Arr.cmp(Str, ['a'])(['a']) // 0
Arr.cmp(Str, ['a'])(['b']) // -1
Arr.cmp(Str, ['b'])(['a']) // 1
Arr.cmp(Str, ['a'])(['a', 'b']) // -1
Arr.cmp(Str, ['a', 'b'])(['a']) // 1
Arr.cmp(Str, ['a', 'b'])(['a', 'b']) // 0
Arr.cmp(Str, ['a', 'b', 'c'])(['a', 'b']) // 1
Arr.cmp(Str, ['a', 'b', 'c'])(['a', 'b', 'c']) // 0
Since
4.0.0
Name |
---|
A |
Name | Type | Description |
---|---|---|
cmp |
ComparableModule <A > |
the comparator module |
a |
T <A > |
the first array to compare |
fn
the unary function which returns
b
is greater then a
b
is less than a
a
and b
are equal▸ (b
): ComparableResult
Name | Type |
---|---|
b |
T <A > |
▸ cmp<A
>(cmp
): (a
: T
<A
>, b
: T
<A
>) => ComparableResult
Compares two arrays T<A>
with a given Comparable<A>
.
Example
import { Arr, Str } from 'tiinvo';
const cmpstr = Arr.cmp(Str.cmp);
cmpstr(['a'], ['a']) // 0
cmpstr(['a'], ['b']) // -1
cmpstr(['b'], ['a']) // 1
cmpstr(['a'], ['a', 'b']) // -1
cmpstr(['a', 'b'], ['a']) // 1
cmpstr(['a', 'b'], ['a', 'b']) // 0
cmpstr(['a', 'b', 'c'], ['a', 'b']) // 1
cmpstr(['a', 'b', 'c'], ['a', 'b', 'c']) // 0
Since
4.0.0
Name |
---|
A |
Name | Type | Description |
---|---|---|
cmp |
Comparable <A > |
the comparator |
fn
the binary function which returns
a
is greater then b
a
is less than b
a
and b
are equal▸ (a
, b
): ComparableResult
Name | Type |
---|---|
a |
T <A > |
b |
T <A > |
▸ cmp<A
>(cmp
): (a
: T
<A
>, b
: T
<A
>) => ComparableResult
Compares two arrays T<A>
with a given ComparableModule<A>
.
Example
import { Arr, Str } from 'tiinvo';
const cmpstr = Arr.cmp(Str);
cmpstr(['a'], ['a']) // 0
cmpstr(['a'], ['b']) // -1
cmpstr(['b'], ['a']) // 1
cmpstr(['a'], ['a', 'b']) // -1
cmpstr(['a', 'b'], ['a']) // 1
cmpstr(['a', 'b'], ['a', 'b']) // 0
cmpstr(['a', 'b', 'c'], ['a', 'b']) // 1
cmpstr(['a', 'b', 'c'], ['a', 'b', 'c']) // 0
Since
4.0.0
Name |
---|
A |
Name | Type | Description |
---|---|---|
cmp |
ComparableModule <A > |
the comparator module |
fn
the binary function which returns
a
is greater then b
a
is less than b
a
and b
are equal▸ (a
, b
): ComparableResult
Name | Type |
---|---|
a |
T <A > |
b |
T <A > |
▸ eq<A
>(e
, a
, b
): boolean
Compares two arrays T<A>
with a given Equatable<a>
and returns true if are identical.
import { Arr, Str } from 'tiinvo';
Arr.eq(Str.eq, ['a'], ['a']) // true
Arr.eq(Str.eq, ['a'], ['b']) // false
Arr.eq(Str.eq, ['b'], ['a']) // false
Arr.eq(Str.eq, ['a'], ['a', 'b']) // false
Arr.eq(Str.eq, ['a', 'b'], ['a']) // false
Arr.eq(Str.eq, ['a', 'b'], ['b', 'a']) // false
Arr.eq(Str.eq, ['a', 'b'], ['a', 'b']) // true
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type | Description |
---|---|---|
e |
Equatable <A > |
the equatable functor |
a |
T <A > |
the first array |
b |
T <A > |
the second array |
boolean
a
and b
are the equal▸ eq<A
>(e
, a
, b
): boolean
Compares two arrays T<A>
with a given EquatableModule<a>
and returns true if are identical.
import { Arr, Str } from 'tiinvo';
Arr.eq(Str, ['a'], ['a']) // true
Arr.eq(Str, ['a'], ['b']) // false
Arr.eq(Str, ['b'], ['a']) // false
Arr.eq(Str, ['a'], ['a', 'b']) // false
Arr.eq(Str, ['a', 'b'], ['a']) // false
Arr.eq(Str, ['a', 'b'], ['b', 'a']) // false
Arr.eq(Str, ['a', 'b'], ['a', 'b']) // true
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type | Description |
---|---|---|
e |
EquatableModule <A > |
the equatable functor module |
a |
T <A > |
the first array |
b |
T <A > |
the second array |
boolean
a
and b
are the equal▸ eq<A
>(e
, a
): Unary
<T
<A
>, boolean
>
Given an Equatable<A>
and an array T<A>
, returns a Fn.Unary<T<A>, boolean>
function to compare a
and b
.
import { Arr, Str } from 'tiinvo';
const eq = Arr.eq(Str.eq);
Arr.eq(Str.eq, ['a'])(['a']) // true
Arr.eq(Str.eq, ['a'])(['b']) // false
Arr.eq(Str.eq, ['b'])(['a']) // false
Arr.eq(Str.eq, ['a'])(['a', 'b']) // false
Arr.eq(Str.eq, ['a', 'b'])(['a']) // false
Arr.eq(Str.eq, ['a', 'b'])(['b', 'a']) // false
Arr.eq(Str.eq, ['a', 'b'])(['a', 'b']) // true
Since
4.0.0
Name |
---|
A |
Name | Type | Description |
---|---|---|
e |
Equatable <A > |
the equatable functor |
a |
T <A > |
the array |
the unary function
▸ eq<A
>(e
, a
): Unary
<T
<A
>, boolean
>
Given an EquatableModule<A>
and an array T<A>
, returns a Fn.Unary<T<A>, boolean>
function to compare a
and b
.
import { Arr, Str } from 'tiinvo';
Arr.eq(Str, ['a'])(['a']) // true
Arr.eq(Str, ['a'])(['b']) // false
Arr.eq(Str, ['b'])(['a']) // false
Arr.eq(Str, ['a'])(['a', 'b']) // false
Arr.eq(Str, ['a', 'b'])(['a']) // false
Arr.eq(Str, ['a', 'b'])(['b', 'a']) // false
Arr.eq(Str, ['a', 'b'])(['a', 'b']) // true
Since
4.0.0
Name |
---|
A |
Name | Type | Description |
---|---|---|
e |
EquatableModule <A > |
the equatable functor module |
a |
T <A > |
the array |
the unary function
▸ eq<A
>(e
): Binary
<T
<A
>, T
<A
>, boolean
>
Given an Equatable<a>
, returns a Fn.Binary<t<a>, t<a>, boolean>
function to compare a
and b
.
import { Arr, Str } from 'tiinvo';
const eq = Arr.eq(Str.eq);
eq(['a'], ['a']) // true
eq(['a'], ['b']) // false
eq(['b'], ['a']) // false
eq(['a'], ['a', 'b']) // false
eq(['a', 'b'], ['a']) // false
eq(['a', 'b'], ['b', 'a']) // false
eq(['a', 'b'], ['a', 'b']) // true
Since
4.0.0
Name |
---|
A |
Name | Type | Description |
---|---|---|
e |
Equatable <A > |
the equatable functor |
the binary function
▸ eq<A
>(e
): Binary
<T
<A
>, T
<A
>, boolean
>
Given an EquatableModule<a>
, returns a Fn.Binary<t<a>, t<a>, boolean>
function to compare a
and b
.
import { Arr, Str } from 'tiinvo';
const eq = Arr.eq(Str);
eq(['a'], ['a']) // true
eq(['a'], ['b']) // false
eq(['b'], ['a']) // false
eq(['a'], ['a', 'b']) // false
eq(['a', 'b'], ['a']) // false
eq(['a', 'b'], ['b', 'a']) // false
eq(['a', 'b'], ['a', 'b']) // true
Since
4.0.0
Name |
---|
A |
Name | Type | Description |
---|---|---|
e |
EquatableModule <A > |
the equatable functor module |
the binary function
▸ concat<A
>(a
, b
): A
Concates b
and a
without modifying the original arrays.
import { Arr } from 'tiinvo';
Arr.concat([10], [20]) // [10, 20]
Since
4.0.0
Name | Type |
---|---|
A |
extends any [] |
Name | Type | Description |
---|---|---|
a |
A |
the first array |
b |
A |
the second array |
A
the concatenated array
▸ concat<A
>(a
): Unary
<A
, A
>
Returns a Unary<a, a>
which concatenates b
and a
without modifying the original arrays.
import { Arr } from 'tiinvo';
Arr.concat([10])([20]) // [20, 10]
Since
4.0.0
Name | Type |
---|---|
A |
extends any [] |
Name | Type | Description |
---|---|---|
a |
A |
the second array |
Unary
<A
, A
>
the unary function
▸ contains<A
>(a
, b
): boolean
Returns true
if an array A
contains b
.
import { Arr } 'tiinvo';
Arr.contains(['a'], 'a') // true
Arr.contains(['a'], 'b') // false
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type |
---|---|
a |
T <A > |
b |
A |
boolean
b
is into a
▸ contains<A
>(a
): Unary
<T
<A
>, boolean
>
Checks if the given argument b
is contained by the array passed to the Fn.Unary<t<a>, boolean>
function.
import { Arr } 'tiinvo';
Arr.contains('a')(['a']) // true
Arr.contains('a')(['b']) // false
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type | Description |
---|---|---|
a |
A |
the value which should be checked |
the unary function
▸ every<A
>(a
, p
): boolean
Determines whether all the members of an array A
satisfy the specified predicate p
.
import { Arr, Num } 'tiinvo';
Arr.every([10, 20], Num.isEven) // true
Arr.every([10, 21], Num.isEven) // false
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type |
---|---|
a |
T <A > |
p |
T <A > |
boolean
a
satisfies p
▸ every<A
>(a
): Unary
<T
<A
>, boolean
>
Returns a Fn.Unary<t<a>, boolean>
which checks if the every element of the array T<A>
satisfy the predicate a
import { Arr, Num } 'tiinvo';
Arr.every(Num.isEven)([10, 20]) // true
Arr.every(Num.isEven)([10, 21]) // false
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the predicate |
the unary function
▸ from<T
>(arrayLike
): T
[]
Creates an array from an array-like object.
import { Arr } 'tiinvo';
Arr.from([1, 2, 3]) // [1, 2, 3]
Arr.from(new Set([1, 2, 3])) // [1, 2, 3]
Since
4.0.0
Name |
---|
T |
Name | Type |
---|---|
arrayLike |
ArrayLike <T > |
T
[]
the array
node_modules/typescript/lib/lib.es2015.core.d.ts:72
▸ from<T
, U
>(arrayLike
, mapfn
, thisArg?
): U
[]
Creates an array from an array-like object.
import { Arr } 'tiinvo';
Arr.from([1, 2, 3]) // [1, 2, 3]
Arr.from(new Set([1, 2, 3])) // [1, 2, 3]
Since
4.0.0
Name |
---|
T |
U |
Name | Type |
---|---|
arrayLike |
ArrayLike <T > |
mapfn |
(v : T , k : number ) => U |
thisArg? |
any |
U
[]
the array
node_modules/typescript/lib/lib.es2015.core.d.ts:80
▸ from<T
>(iterable
): T
[]
Creates an array from an array-like object.
import { Arr } 'tiinvo';
Arr.from([1, 2, 3]) // [1, 2, 3]
Arr.from(new Set([1, 2, 3])) // [1, 2, 3]
Since
4.0.0
Name |
---|
T |
Name | Type |
---|---|
iterable |
Iterable <T > | ArrayLike <T > |
T
[]
the array
node_modules/typescript/lib/lib.es2015.iterable.d.ts:83
▸ from<T
, U
>(iterable
, mapfn
, thisArg?
): U
[]
Creates an array from an array-like object.
import { Arr } 'tiinvo';
Arr.from([1, 2, 3]) // [1, 2, 3]
Arr.from(new Set([1, 2, 3])) // [1, 2, 3]
Since
4.0.0
Name |
---|
T |
U |
Name | Type |
---|---|
iterable |
Iterable <T > | ArrayLike <T > |
mapfn |
(v : T , k : number ) => U |
thisArg? |
any |
U
[]
the array
node_modules/typescript/lib/lib.es2015.iterable.d.ts:91
▸ fill<A
>(a
, b
, start?
, end?
): T
<A
>
Fills an array T<A>
with a
from index start
to end
.
This does not modify the original array.
import { Arr } from 'tiinvo';
const x = Arr.make(4)
Arr.fill(x, 10, 0, 3) // [10, 10, 10, 10]
Arr.fill(x, 10) // [10, 10, 10, 10]
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type | Description |
---|---|---|
a |
T <any > |
the array |
b |
A |
- |
start? |
number |
|
end? |
number |
T
<A
>
▸ fill<A
>(a
, b?
, start?
): (a
: T
<any
>, start2?
: number
, end2?
: number
) => T
<A
>
Fills an array T<A>
with a
from index start
to end
.
This does not modify the original array.
import { Arr } from 'tiinvo';
const x = Arr.make(4)
Arr.fill(10, 0, 3)(x) // [10, 10, 10, 10]
Arr.fill(10)(x) // [10, 10, 10, 10]
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type | Description |
---|---|---|
a |
A |
the value to fill the array |
b? |
number |
the start index |
start? |
number |
the end index |
fn
▸ (a
, start2?
, end2?
): T
<A
>
Name | Type |
---|---|
a |
T <any > |
start2? |
number |
end2? |
number |
T
<A
>
▸ filter<A
>(a
, p
): T
<A
>
Returns the elements of an array A
that meet the condition specified in a predicate p
.
import { Arr, Num } 'tiinvo';
const x = [10, 20, 30];
Arr.filter(x, Num.gt(10)) // [20, 30]
Arr.filter(Num.gt(10))(x) // [20, 30]
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the array to filter |
p |
T <A > |
the predicate to satisfy |
T
<A
>
▸ filter<A
>(a
): Unary
<T
<A
>, T
<A
>>
Returns a Unary<t<a>, t<a>>
. Calling this function will filter the array passed as argument with the predicate a
.
import { Arr, Num } 'tiinvo';
const x = [10, 20, 30];
Arr.filter(x, Num.gt(10)) // [20, 30]
Arr.filter(Num.gt(10))(x) // [20, 30]
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the Predicate.t<a> |
▸ find<A
>(a
, p
): T
<A
>
Finds the first value a
with a given predicate p
and returns Option.some<a>
if found, otherwise returns Option.none
.
import { Arr, Num } 'tiinvo';
const x = [10, 20, 30];
Arr.find(x, Num.gt(10)) // 20
Arr.find(x, Num.gt(30)) // null
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type |
---|---|
a |
T <A > |
p |
T <A > |
T
<A
>
▸ find<A
>(a
): Unary
<T
<A
>, T
<A
>>
Finds the first value a
with a given predicate p
and returns Option.some<a>
if found, otherwise returns Option.none
.
import { Arr, Num } 'tiinvo';
const x = [10, 20, 30];
Arr.find(Num.gt(10))(x) // 20
Arr.find(Num.gt(30))(x) // null
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the search predicate |
▸ flat<A
, D
>(a
, d?
): FlatArray
<A
, D
>
Flatterns an array.
Example
import { Arr } from 'tiinvo';
const x = [[10, 20], [['hello', 'world']]]
Arr.flat(x) // [10, 20, ['hello', 'world']]
Arr.flat(x, 2) // [10, 20, 'hello', 'world']
Since
4.0.0
Name | Type | Description |
---|---|---|
A |
extends any [] |
array’s type |
D |
extends number = 1 |
flattern depth |
Name | Type | Description |
---|---|---|
a |
A |
the array to flattern |
d? |
D |
the depth (optional) |
FlatArray
<A
, D
>
the flattened array
▸ flat<A
, D
>(a?
): Unary
<A
, FlatArray
<A
, D
>>
Returns a Unary<a, FlatArray<a, d>>
which flatterns an array b
with the depth a
.
Example
import { Arr } from 'tiinvo';
const x = [[10, 20], [['hello', 'world']]]
Arr.flat()(x) // [10, 20, ['hello', 'world']]
Arr.flat(2)(x) // [10, 20, 'hello', 'world']
Since
4.0.0
Name | Type | Description |
---|---|---|
A |
extends any [] |
array’s type |
D |
extends number = 1 |
flattern depth type |
Name | Type | Description |
---|---|---|
a? |
D |
the depth (optional) |
Unary
<A
, FlatArray
<A
, D
>>
the unary function
▸ includes<A
>(a
, b
): boolean
Determines whether an array includes a certain element, returning true
or false
as appropriate.
Example
import { Arr } from 'tiinvo'
const x = [10, 20, 30]
Arr.includes(x, 30) // true
Arr.includes(30)(x) // true
Arr.includes(x, 40) // false
Arr.includes(40)(x) // false
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the array |
b |
A |
the value to look up for |
boolean
b
has been found▸ includes<A
>(a
): Unary
<T
<A
>, boolean
>
Determines whether an array includes a certain element, returning true
or false
as appropriate.
Example
import { Arr } from 'tiinvo'
const x = [10, 20, 30]
Arr.includes(x, 30) // true
Arr.includes(30)(x) // true
Arr.includes(x, 40) // false
Arr.includes(40)(x) // false
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type | Description |
---|---|---|
a |
A |
the value to look for |
the unary function which returns
true
if a
has been found in the passed arrayfalse
otherwise▸ length<A
>(t
): number
Gets the length of the array. This is a number one higher than the highest index in the array.
Example
import { Arr } from 'tiinvo';
Arr.length([]) // 0
Arr.length([1]) // 1
Arr.length([1, 2, 3]) // 3
Since
4.0.0
Name |
---|
A |
Name | Type | Description |
---|---|---|
t |
T <A > |
the array |
number
the length of the array
▸ join<A
, B
>(a
, b?
): string
Adds all the elements of an array into a string, separated by the specified separator string.
Important, despites native JavaScript implementation, the default separator is an empty string if not specified
Example
import { Arr } from 'tiinvo'
const x = [10, 20, 30]
Arr.join(x, '-') // '10-20-30'
Arr.join(x) // '102030'
Since
4.0.0
Name | Type | Description |
---|---|---|
A |
extends any [] |
array’s type |
B |
extends string |
the string type to use as divider |
Name | Type | Description |
---|---|---|
a |
A |
the array |
b? |
B |
the string used as divider |
string
the concatenated string
▸ join<A
, B
>(a?
): Unary
<A
, string
>
Returns a Unary<t<a>, string>
function which adds all the elements of an array into a string, separated by the specified separator string a
.
Important, despites native JavaScript implementation, the default separator is an empty string if not specified
Example
import { Arr } from 'tiinvo'
const x = [10, 20, 30]
Arr.join('-')(x) // '10-20-30'
Arr.join()(x) // '102030'
Since
4.0.0
Name | Type | Description |
---|---|---|
A |
extends any [] |
array’s type |
B |
extends string |
the string type to use as divider |
Name | Type | Description |
---|---|---|
a? |
B |
the string used as divider |
Unary
<A
, string
>
the concatenated string
▸ map<A
, B
>(a
, m
): T
<B
>
Maps an array of elements a
to an array of elements b
using the mapping function m
.
Example
import { Arr, Num } from 'tiinvo';
const x = [1, 2, 3];
const m = Num.mul(2);
Arr.map(x, m) // [2, 4, 6]
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
B |
the return type of the mappable functor |
Name | Type | Description |
---|---|---|
a |
T <A > |
the array |
m |
Mappable <A , B > |
the functors used to map the array |
T
<B
>
the mapped array
▸ map<A
, B
>(a
): Unary
<T
<A
>, T
<B
>>
Maps an array of elements a
to an array of elements b
using the mapping function m
.
Example
import { Arr, Num } from 'tiinvo';
const x = [1, 2, 3];
const m = Num.mul(2);
Arr.map(m)(x) // [2, 4, 6]
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
B |
the return type of the mappable functor |
Name | Type | Description |
---|---|---|
a |
Mappable <A , B > |
the functors used to map the array |
the unary function which takes an array b
and returns an array c
with type T<B>
▸ none<A
>(a
, m
): boolean
Returns true if all elements of a
do not meet the condition specified in the predicate m
.
Example
import { Arr, Num } from 'tiinvo'
const x = [1, 3, 5]
const p = Num.isEven
Arr.none(x, p) // true
Arr.none(p)(x) // true
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the array |
m |
T <A > |
the predicate Predicate.t<a> |
boolean
m
▸ none<A
>(a
): Unary
<T
<A
>, boolean
>
Returns a Unary<t<a>, boolean> which once called returns true if all elements of
b do not meet the condition specified in the predicate
a`.
@example
import { Arr, Num } from 'tiinvo'
const x = [1, 3, 5]
const p = Num.isEven
Arr.none(x, p) // true
Arr.none(p)(x) // true
@template A array’s type
@param a the predicate Predicate.t<a>
@returns the unary function which takes an array T<A>
and returns
true
if every element does not satisfy the predicate a
false
otherwiseSince
4.0.0
Name |
---|
A |
Name | Type |
---|---|
a |
T <A > |
▸ of<T
>(...items
): T
[]
Returns a new array from a set of elements.
import { Arr } 'tiinvo';
Arr.of(1, 2, 3) // [1, 2, 3]
Since
4.0.0
Name |
---|
T |
Name | Type | Description |
---|---|---|
...items |
T [] |
A set of elements to include in the new array object. |
T
[]
the new array
node_modules/typescript/lib/lib.es2015.core.d.ts:86
▸ reduce<A
, B
>(a
, r
, b
): B
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.
Example
import { Arr, Num } from 'tiinvo'
const x = [1, 2, 3, 4, 5]
Arr.reduce(x, Num.add, 0) // 15
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
B |
returned value type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the array |
r |
Reducer <A , B > |
the reducer |
b |
B |
- |
B
the reduced value
▸ reduce<A
, B
>(a
, r
): (b
: T
<A
>) => B
Sets a callback function for all the elements in an array
passed to the returned Unary<t<a>, b>
.
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.
Example
import { Arr, Num } from 'tiinvo'
const x = [1, 2, 3, 4, 5]
Arr.reduce(Num.add, 0)(x) // 15
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
B |
returned value type |
Name | Type | Description |
---|---|---|
a |
Reducer <A , B > |
the array |
r |
B |
the reducer |
fn
the reduced value
▸ (b
): B
Name | Type |
---|---|
b |
T <A > |
B
▸ reduceRight<A
, B
>(a
, r
, b
): B
Calls the specified callback function for all the elements in an array, in descending order.
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.
Example
import { Arr, Num } from 'tiinvo'
const x = [1, 2, 3, 4, 5]
Arr.reduceRight(x, Num.sub, 0) // -15
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
B |
returned value type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the array |
r |
Reducer <A , B > |
the reducer |
b |
B |
- |
B
the reduced value
▸ reduceRight<A
, B
>(a
, r
): Unary
<T
<A
>, B
>
Calls the specified callback function for all the elements in an array, in descending order. 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. Sets a callback function for all the elements in an array, in descending order.
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.
Example
import { Arr, Num } from 'tiinvo'
const x = [1, 2, 3, 4, 5]
Arr.reduceRight(Num.sub, 0)(x) // -15
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
B |
returned value type |
Name | Type | Description |
---|---|---|
a |
Reducer <A , B > |
the array |
r |
B |
the reducer |
the reducer unary function
▸ reverse<A
>(a
): T
<A
>
Reverses the elements in an array in place without mutating the original array.
Example
import { Arr } 'tiinvo';
Arr.reverse([10, 20, 30]) // [30, 20, 10]
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the array |
T
<A
>
the reversed array
▸ slice<A
>(a
, s?
, e?
): A
Returns a copy of a section of an array.
For both start and end, a negative index can be used to indicate an offset from the end of the array.
For example, -2 refers to the second to last element of the array.
Example
import { Arr } from 'tiinvo'
const x = [10, 20, 30]
Arr.slice(x) // [10, 20, 30]
Arr.slice(x, 2) // [30]
Arr.slice(x, 1, 2) // [20]
Since
4.0.0
Name | Type | Description |
---|---|---|
A |
extends any [] |
the array type |
Name | Type | Description |
---|---|---|
a |
A |
the array |
s? |
number |
the optional start index |
e? |
number |
- |
A
the sliced array
▸ slice<A
>(a?
, s?
): Unary
<A
, A
>
Returns a Fn.Unary<a, a>
which copies a section of an array.
For both start and end, a negative index can be used to indicate an offset from the end of the array.
For example, -2 refers to the second to last element of the array.
Example
import { Arr } from 'tiinvo'
const x = [10, 20, 30]
Arr.slice()(x) // [10, 20, 30]
Arr.slice(2)(x) // [30]
Arr.slice(1, 2)(x) // [20]
Since
4.0.0
Name | Type | Description |
---|---|---|
A |
extends any [] |
the array type |
Name | Type | Description |
---|---|---|
a? |
number |
the array |
s? |
number |
the optional start index |
Unary
<A
, A
>
the unary function which slices the array
▸ some<A
>(a
, p
): boolean
Determines whether some members of an array A
satisfy the specified predicate p
.
Example
import { Arr, Num } from 'tiinvo'
Arr.some([1, 2, 3], Num.isEven) // true
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the array |
p |
T <A > |
the predicate |
boolean
return true if some values satisfy the predicate
▸ some<A
>(a
): Unary
<T
<A
>, boolean
>
Returns a Unary<t<a>, boolean>
function which determines whether some members of an array b
satisfy the specified predicate a
.
Example
import { Arr, Num } from 'tiinvo'
Arr.some(Num.isEven)([1, 2, 3]) // true
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the predicate |
the unary function which returns
true
if some values satisfy the predicatefalse
otherwise▸ sort<A
>(a
, cmp
): T
<A
>
Sorts an array of elements a
using the specified comparator cmp
.
Example
import { Arr, Num } from 'tiinvo'
const x = [3, 1, 2, 5, 4]
const s = Num.asc;
Arr.sort(x, s) // [1, 2, 3, 4, 5]
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the array |
cmp |
Comparable <A > |
the comparable functor |
T
<A
>
the sorted array
▸ sort<A
>(a
): Unary
<T
<A
>, T
<A
>>
Returns a Unary<t<a>, t<a>>
function which sorts an array of elements b
using the specified comparator a
.
Example
import { Arr, Num } from 'tiinvo'
const s = Arr.sort(Num.asc);
s([3, 1, 2, 5, 4]) // [1, 2, 3, 4, 5]
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type | Description |
---|---|---|
a |
Comparable <A > |
the comparable functor |
the unary function which sorts the array
▸ filterMap<A
, B
>(a
, mod
): T
<B
>
Maps with the mod.map
function an array T<A>
by removing all elements that do not satisfy the predicate mod.filter
.
The filter occurs before mapping the elements.
Example
import { Arr, Functors, Num } from 'tiinvo';
const x = [-10, 10]
const mod: Functors.FilterMappableModule<number, number> = {
filter: Num.gt(0),
map: Num.add(10),
};
Arr.filterMap(x, mod) // [20]
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
B |
returning array’s type |
Name | Type |
---|---|
a |
T <A > |
mod |
FilterMappableModule <A , B > |
T
<B
>
▸ filterMap<A
, B
>(a
): Unary
<T
<A
>, T
<B
>>
Maps with the mod.map
function an array T<A>
by removing all elements that do not satisfy the predicate mod.filter
.
The filter occurs before mapping the elements.
Example
import { Arr, Functors, Num } from 'tiinvo';
const x = [-10, 10]
const mod: Functors.FilterMappableModule<number, number> = {
filter: Num.gt(0),
map: Num.add(10),
};
Arr.filterMap(mod)(x) // [20]
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
B |
returning array’s type |
Name | Type | Description |
---|---|---|
a |
FilterMappableModule <A , B > |
the filter mappable functor |
the unary function
▸ filterReduce<A
, B
>(a
, mod
): B
Like a normal array reduce, but after a filter has been applied on each iteration.
If the filter is satisfied, then the reduce occurs for the current element, otherwise it skips.
Example
import { Arr, Functors, Num } from 'tiinvo'
const mod: Functors.FilterReduceableModule<number, number> = {
default: 0,
filter: Num.isPositive,
reduce: Num.add,
}
const x = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
Arr.filterReduce(x, mod) // 15
Arr.filterReduce(mod)(x) // 15
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
B |
returning reduced type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the array to filter and reduce |
mod |
FilterReduceableModule <A , B > |
the functor |
B
the filtered and reduced output
▸ filterReduce<A
, B
>(a
): Unary
<T
<A
>, B
>
Like a normal array reduce, but after a filter has been applied on each iteration.
If the filter is satisfied, then the reduce occurs for the current element, otherwise it skips.
Example
import { Arr, Functors, Num } from 'tiinvo'
const mod: Functors.FilterReduceableModule<number, number> = {
default: 0,
filter: Num.isPositive,
reduce: Num.add,
}
const x = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
Arr.filterReduce(x, mod) // 15
Arr.filterReduce(mod)(x) // 15
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
B |
returning value type |
Name | Type | Description |
---|---|---|
a |
FilterReduceableModule <A , B > |
the functor module type |
the unary function
▸ flatMap<A
, B
>(a
, m
): T
<B
>
Maps a matrix t<t<a>>
to a t<b>
using the mapping function m
.
Example
import { Arr, Num } from 'tiinvo';
const x = [[2, 3], [4, 5]]
Arr.flatMap(x, Num.add(1)) // [3, 4, 5, 6]
Since
4.0.0
Name | Description |
---|---|
A |
the matrix elements’ type |
B |
the flatterned mapped array type |
Name | Type | Description |
---|---|---|
a |
T <T <A >> |
the matrix |
m |
Mappable <A , B > |
the mappable functor |
T
<B
>
the flatmapped array
▸ flatMap<A
, B
>(a
): Unary
<T
<T
<A
>>, T
<B
>>
Returns a Fn.Unary<a[][]>, b[]>
which aps a matrix T<A>[]
to a b[]
using the mapping function a
.
Example
import { Arr, Num } from 'tiinvo';
const x = [[2, 3], [4, 5]]
Arr.flatMap(Num.add(1))(x) // [3, 4, 5, 6]
Since
4.0.0
Name | Description |
---|---|
A |
the matrix elements’ type |
B |
the flatterned mapped array type |
Name | Type | Description |
---|---|---|
a |
Mappable <A , B > |
the mappable functor |
the unary function
▸ make<A
>(size
, d?
): A
extends None
? T
<None
> : T
<A
>
Creates a new array t<Option.None>
of a given size.
If a default value d
is specified, then the returning array will be t<typeof d>
The default value could be either an arbitrary type or a Fn.Unary<number, a>
type.
If a unary function is passed as d
, the returning array will be t<ReturnType<d>>
.
Example
import { Arr } from 'tiinvo'
Arr.make(3) // [undefined, undefined, undefined]
Arr.make(3, 'hello') // ['hello', 'hello', 'hello']
Since
4.0.0
Name | Type | Description |
---|---|---|
A |
undefined |
the array’s type |
Name | Type | Description |
---|---|---|
size |
number |
the size of the array |
d? |
A |
this is the value used to fill the array |
A
extends None
? T
<None
> : T
<A
>
the array
▸ make<A
>(size
, d?
): A
extends None
? T
<None
> : T
<A
>
Creates a new array t<Option.None>
of a given size.
If a default value d
is specified, then the returning array will be t<typeof d>
The default value could be either an arbitrary type or a Fn.Unary<number, a>
type.
If a unary function is passed as d
, the returning array will be t<ReturnType<d>>
.
Example
import { Arr } from 'tiinvo'
Arr.make(3, x => ((x + 1) * 10).toString(16)) // ['a', '14', '1e']
Since
4.0.0
Name | Type | Description |
---|---|---|
A |
undefined |
the array’s type |
Name | Type | Description |
---|---|---|
size |
number |
the size of the array |
d? |
Unary <number , A > |
a function used to return a value for every index of an array |
A
extends None
? T
<None
> : T
<A
>
the array
▸ partition<A
>(a
, f
): [T
<A
>, T
<A
>]
Split an array T<A>
into a tuple [T<A>, T<A>]
based on predicate f
;
If the element a
of T<A>
satisfies the predicate f
, then it will be pushed to
the first element of the tuple, otherwise to the second.
Example
import { Arr, Num } from 'tiinvo'
const a = [1, 2, 3, 4, 5]
Arr.partition(a, Num.isEven) // [[2, 4], [1, 3, 5]]
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the array |
f |
Filterable <A > |
the filterable functor |
the partitioned array
▸ partition<A
>(a
): Unary
<T
<A
>, [T
<A
>, T
<A
>]>
Returns a Fn.Unary<T<A>, [T<A>, T<A>]>
which splits an array T<A>
into a tuple [T<A>, T<A>]
based on predicate f
;
If the element a
of T<A>
satisfies the predicate f
, then it will be pushed to
the first element of the tuple, otherwise to the second.
Example
import { Arr, Num } from 'tiinvo'
const a = [1, 2, 3, 4, 5]
Arr.partition(Num.isEven)(a) // [[2, 4], [1, 3, 5]]
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type | Description |
---|---|---|
a |
Filterable <A > |
the filterable functor |
the unary function which takes an array T<A>
as an argument and returns
a tuple [T<A>, T<A>]
▸ random<A
>(a
): T
<A
>
Returns a random element of an array A
.
If the array is empty, returns Option.None
import { Arr } 'tiinvo';
Arr.random(['a', 'b', 'c']) // 'a' or 'b' or 'c'
Since
4.0.0
Name | Description |
---|---|
A |
array’s type |
Name | Type | Description |
---|---|---|
a |
A [] |
the array |
T
<A
>
a random element of the array
Option.Some<A>
if the array is not emptyOption.None
if the array is empty▸ shuffle<A
>(a
): T
<A
>
Shuffles an array
Example
import { Arr } from 'tiinvo'
Arr.shuffle([10, 20, 30]) // could be [10, 30, 20] or [20, 30, 10] or [30, 20, 10] or ...
Since
4.0.0
Name | Description |
---|---|
A |
the array’s type |
Name | Type | Description |
---|---|---|
a |
T <A > |
the array |
T
<A
>
the shuffled array
▸ zip<A
>(a
, b
): T
<A
>
Returns an array of pairs from the two arrays with the length of the shorter one.
Example
import { Arr } from 'tiinvo'
const a0 = [1, 2]
const a1 = [3, 4, 5]
Arr.zip(a0, a1) // [[1, 3], [2, 4]]
Since
4.0.0
Name | Type | Description |
---|---|---|
A |
extends any [] |
the array’s type |
Name | Type | Description |
---|---|---|
a |
A |
the first array |
b |
A |
the second array |
T
<A
>
the zipped array
Returns a Fn.Unary<a, t<a>>
which once called returns an array of pairs
from the two arrays with the length of the shorter one.
Example
import { Arr } from 'tiinvo'
const a0 = [1, 2]
const a1 = [3, 4, 5]
Arr.zip(a1)(a0) // [[1, 3], [2, 4]]
Since
4.0.0
Name | Type | Description |
---|---|---|
A |
extends any [] |
the array’s type |
Name | Type | Description |
---|---|---|
a |
A |
the second array |
the unary function which zips the array
▸ empty(t
): boolean
Returns true
if the array t<any>
is empty.
import { Arr } from 'tiinvo';
Arr.empty([]) // true
Arr.empty(['a']) // false
Since
4.0.0
Name | Type | Description |
---|---|---|
t |
T <any > |
the array |
boolean
true
if is emptyfalse
otherwise▸ populated(t
): boolean
Returns true
if the array t<any>
is populated.
import { Arr } from 'tiinvo';
Arr.populated([]) // false
Arr.populated(['a']) // true
Since
4.0.0
Name | Type | Description |
---|---|---|
t |
T <any > |
the array |
boolean
true
if the array is populatedfalse
otherwise