Ƭ T<A>: Iterable<A> & { [indexer]: () => Readonly<Record<number, A>> ; [iterator]: () => Iterator<A, any, undefined> }
A Sequence.T<A> is an immutable and iterable list of elements a in a particular order.
| Name |
|---|
A |
Try to deserialize a string to a Sequence.T<A>
Example
import { Sequence } from 'tiinvo'
const x = Sequence.fromString<number>(`10,20,30`) as Sequence.T<number>;
const t1 = Sequence.make(10, 20, 30)
const t2 = Sequence.make(10, 30, 20)
Sequence.eq(x, t1) // true
Sequence.eq(x, t2) // false
Since
4.0.0
| Name | Type | Description |
|---|---|---|
A |
unknown |
the Sequence’s expected element type |
| Name | Type | Description |
|---|---|---|
x |
string |
the string |
Result.Ok<Sequence.T<A>> if the deserialization is successfulResult.Err otherwise▸ make<A>(v): T<A>
Makes a new Sequence.T<A> from an array of A.
Example
import { Sequence } from 'tiinvo'
Sequence.make([10, 20, 30]) // Sequence.T<number>
Sequence.make([1, 2], [3, 4]) // Sequence.T<number[]>
Since
4.0.0
| Name | Description |
|---|---|
A |
the type |
| Name | Type | Description |
|---|---|---|
v |
A[] |
the array of initial values |
T<A>
the Sequence.T<A>
▸ make<A>(...v): T<A>
Makes a new Sequence.T<A> from a list of arguments a.
Example
import { Sequence } from 'tiinvo'
Sequence.make(10, 20, 30) // Sequence.T<number>
Since
4.0.0
| Name | Description |
|---|---|
A |
the type |
| Name | Type | Description |
|---|---|---|
...v |
A[] |
the list of initial values |
T<A>
the Sequence.T<A>
▸ guard(x): x is T<unknown>
Checks if a value x is a Sequence.T<unknown>.
Example
import { Sequence } from 'tiinvo'
Sequence.guard(10) // false
Sequence.guard([10, 20, 30]) // false
Sequence.guard(Sequence.make()) // true
Since
4.0.0
| Name | Type | Description |
|---|---|---|
x |
unknown |
the value to guard |
x is T<unknown>
true if x is Sequence.T<unknown>false otherwise▸ guardOf<A>(g): (x: unknown) => x is T<A>
Checks if the parameter x is a Sequence.T<A>
Example
import { Sequence, Num, Str } from 'tiinvo'
const s0 = Sequence.make<number | string>(1, 'hello', 2)
const s1 = Sequence.make('hello', 'world')
const isStrSequence = Sequence.guardOf(Str.guard);
isStrSequence(s0) // false
isStrSequence(s1) // true
Since
4.0.0
| Name |
|---|
A |
| Name | Type | Description |
|---|---|---|
g |
Guardable<A> |
the guard |
fn
the new guard which returns
true if x is a Sequence.T<A>false otherwise▸ (x): x is T<A>
| Name | Type |
|---|---|
x |
unknown |
x is T<A>
▸ cmp<A>(mod, a, b): ComparableResult
Compares two sequences.
Example
import { Sequence, Num } from 'tiinvo'
const s0 = Sequence.make(0, 1, 2)
const s1 = Sequence.make(0, 1, 2)
const s2 = Sequence.make(0, 1, 2, 3)
Sequence.cmp(Num, s0, s1) // 0
Sequence.cmp(Num, s0)(s1) // 0
Sequence.cmp(Num)(s0, s1) // 0
Sequence.cmp(Num, s0, s2) // -1
Sequence.cmp(Num, s0)(s2) // -1
Sequence.cmp(Num)(s0, s2) // -1
Sequence.cmp(Num, s2, s0) // 1
Sequence.cmp(Num, s2)(s0) // 1
Sequence.cmp(Num)(s2, s0) // 1
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
mod |
ComparableModule<A> |
the comparable functor module |
a |
T<A> |
the first sequence |
b |
T<A> |
the last sequence |
the comparison result Functors.ComparableResult
▸ cmp<A>(mod, a, b): ComparableResult
Compares two sequences.
Example
import { Sequence, Num } from 'tiinvo'
const s0 = Sequence.make(0, 1, 2)
const s1 = Sequence.make(0, 1, 2)
const s2 = Sequence.make(0, 1, 2, 3)
Sequence.cmp(Num.cmp, s0, s1) // 0
Sequence.cmp(Num.cmp, s0)(s1) // 0
Sequence.cmp(Num.cmp)(s0, s1) // 0
Sequence.cmp(Num.cmp, s0, s2) // -1
Sequence.cmp(Num.cmp, s0)(s2) // -1
Sequence.cmp(Num.cmp)(s0, s2) // -1
Sequence.cmp(Num.cmp, s2, s0) // 1
Sequence.cmp(Num.cmp, s2)(s0) // 1
Sequence.cmp(Num.cmp)(s2, s0) // 1
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
mod |
Comparable<A> |
the comparable functor |
a |
T<A> |
the first sequence |
b |
T<A> |
the last sequence |
the comparison result Functors.ComparableResult
▸ cmp<A>(mod, a): Unary<T<A>, ComparableResult>
Returns a unary function which compares two Sequence
Example
import { Sequence, Num } from 'tiinvo'
const s0 = Sequence.make(0, 1, 2)
const s1 = Sequence.make(0, 1, 2)
const s2 = Sequence.make(0, 1, 2, 3)
Sequence.cmp(Num, s0)(s1) // 0
Sequence.cmp(Num, s0)(s2) // -1
Sequence.cmp(Num, s2)(s0) // 1
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
mod |
ComparableModule<A> |
the comparable functor module |
a |
T<A> |
the first sequence |
Unary<T<A>, ComparableResult>
the unary function
▸ cmp<A>(mod, a): Unary<T<A>, ComparableResult>
Returns a unary function which compares two Sequence
Example
import { Sequence, Num } from 'tiinvo'
const s0 = Sequence.make(0, 1, 2)
const s1 = Sequence.make(0, 1, 2)
const s2 = Sequence.make(0, 1, 2, 3)
Sequence.cmp(Num.cmp, s0)(s1) // 0
Sequence.cmp(Num.cmp, s0)(s2) // 1
Sequence.cmp(Num.cmp, s2)(s0) // -1
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
mod |
Comparable<A> |
the comparable functor |
a |
T<A> |
the first sequence |
Unary<T<A>, ComparableResult>
the unary function
▸ cmp<A>(mod): Binary<T<A>, T<A>, ComparableResult>
Returns a binary function which compares two Sequence
Example
import { Sequence, Num } from 'tiinvo'
const s0 = Sequence.make(0, 1, 2)
const s1 = Sequence.make(0, 1, 2)
const s2 = Sequence.make(0, 1, 2, 3)
Sequence.cmp(Num)(s0, s1) // 0
Sequence.cmp(Num)(s0, s2) // -1
Sequence.cmp(Num)(s2, s0) // 1
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
mod |
ComparableModule<A> |
the comparable functor module |
Binary<T<A>, T<A>, ComparableResult>
the binary function
▸ cmp<A>(mod): Binary<T<A>, T<A>, ComparableResult>
Returns a binary function which compares two Sequence
Example
import { Sequence, Num } from 'tiinvo'
const s0 = Sequence.make(0, 1, 2)
const s1 = Sequence.make(0, 1, 2)
const s2 = Sequence.make(0, 1, 2, 3)
Sequence.cmp(Num.cmp)(s0, s1) // 0
Sequence.cmp(Num.cmp)(s0, s2) // -1
Sequence.cmp(Num.cmp)(s2, s0) // 1
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
mod |
Comparable<A> |
the comparable functor |
Binary<T<A>, T<A>, ComparableResult>
the binary function
▸ eq<A>(mod, a, b): boolean
Checks if two sequences are equal
Example
import { Sequence, Num } from 'tiinvo'
const s0 = Sequence.make(0, 1, 2)
const s1 = Sequence.make(0, 1, 2)
const s2 = Sequence.make(0, 1, 2, 3)
Sequence.eq(Num, s0, s1) // true
Sequence.eq(Num, s0, s2) // false
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
mod |
EquatableModule<A> |
the equatable module functor |
a |
T<A> |
the first Sequence |
b |
T<A> |
the last Sequence |
boolean
true if a and b are equalfalse otherwise▸ eq<A>(mod, a, b): boolean
Checks if two sequences are equal
Example
import { Sequence, Num } from 'tiinvo'
const s0 = Sequence.make(0, 1, 2)
const s1 = Sequence.make(0, 1, 2)
const s2 = Sequence.make(0, 1, 2, 3)
Sequence.eq(Num.cmp, s0, s1) // true
Sequence.eq(Num.cmp, s0, s2) // false
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
mod |
Equatable<A> |
the equatable functor |
a |
T<A> |
the first Sequence |
b |
T<A> |
the last Sequence |
boolean
true if a and b are equalfalse otherwise▸ eq<A>(mod, a): Unary<T<A>, boolean>
Returns a unary function which checks if two sequences are equal
Example
import { Sequence, Num } from 'tiinvo'
const s0 = Sequence.make(0, 1, 2)
const s1 = Sequence.make(0, 1, 2)
const s2 = Sequence.make(0, 1, 2, 3)
const eqs0 = Sequence.eq(Num, s0)
eqs0(s1) // true
eqs0(s2) // false
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
mod |
EquatableModule<A> |
the equatable module functor |
a |
T<A> |
the first Sequence |
the unary function which checks and returns
true if a and b are equalfalse otherwise▸ eq<A>(mod, a): Unary<T<A>, boolean>
Returns a unary function which checks if two sequences are equal
Example
import { Sequence, Num } from 'tiinvo'
const s0 = Sequence.make(0, 1, 2)
const s1 = Sequence.make(0, 1, 2)
const s2 = Sequence.make(0, 1, 2, 3)
const eqs0 = Sequence.eq(Num.cmp, s0)
eqs0(s1) // true
eqs0(s2) // false
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
mod |
Equatable<A> |
the equatable functor |
a |
T<A> |
the first Sequence |
the unary function which checks and returns
true if a and b are equalfalse otherwise▸ eq<A>(mod): Binary<T<A>, T<A>, boolean>
Returns a binary function which checks if two sequences are equal
Example
import { Sequence, Num } from 'tiinvo'
const s0 = Sequence.make(0, 1, 2)
const s1 = Sequence.make(0, 1, 2)
const s2 = Sequence.make(0, 1, 2, 3)
const eq = Sequence.eq(Num);
eq(s0, s1) // true
eq(s0, s2) // false
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
mod |
EquatableModule<A> |
the equatable module functor |
the binary function which checks and returns
true if a and b are equalfalse otherwise▸ eq<A>(mod): Binary<T<A>, T<A>, boolean>
Returns a binary function which checks if two sequences are equal
Example
import { Sequence, Num } from 'tiinvo'
const s0 = Sequence.make(0, 1, 2)
const s1 = Sequence.make(0, 1, 2)
const s2 = Sequence.make(0, 1, 2, 3)
const eq = Sequence.eq(Num.cmp);
eq(s0, s1) // true
eq(s0, s2) // false
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
mod |
Equatable<A> |
the equatable functor |
the binary function which checks and returns
true if a and b are equalfalse otherwise▸ map<A, B>(a, m): T<B>
Maps a Sequence.T<A> to a Sequence.T<B> using the functor Functors.Mappable<a, b>.
Example
import { Sequence, Num } from 'tiinvo'
const s = Sequence.make(1, 2, 3)
Sequence.map(s, Num.mul(2)) // Sequence.t(2, 4, 6)
Since
4.0.0
| Name | Description |
|---|---|
A |
the sequence’s element type |
B |
the mapped sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the sequence |
m |
Mappable<A, B> |
the mappable functor |
T<B>
the mapped sequence
▸ map<A, B>(a): Unary<T<A>, T<B>>
Returns a unary function which maps a Sequence.T<A> to a Sequence.T<B> using the functor Functors.Mappable<a, b>.
Example
import { Sequence, Num } from 'tiinvo'
const s = Sequence.make(1, 2, 3)
Sequence.map(Num.mul(2))(s) // Sequence.t(2, 4, 6)
Since
4.0.0
| Name | Description |
|---|---|
A |
the sequence’s element type |
B |
the mapped sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
Mappable<A, B> |
the sequence |
the unary function which maps Sequence.T to Sequence.T<B>
▸ reduce<A, B>(a, mod, s): B
Reduces all elements a to b of a Sequence.T<A>
Example
import { Sequence, Num } from 'tiinvo'
const s = Sequence.make(10, 20, 30)
Sequence.reduce(s, Num.add, 0) // 60
Since
4.0.0
| Name | Description |
|---|---|
A |
the sequence’s element type |
B |
the reduced value type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the sequence |
mod |
Reduceable<A, B> |
the reducer functor |
s |
B |
the starting reduced value |
B
the reduced value
▸ reduce<A, B>(a, mod): Unary<T<A>, B>
Returns a unary function which reduces all elements a to b of a Sequence.T<A>
Example
import { Sequence, Num } from 'tiinvo'
const s = Sequence.make(10, 20, 30)
Sequence.reduce<number, number>(Num.add, 0)(s) // 60
Since
4.0.0
| Name | Description |
|---|---|
A |
the sequence’s element type |
B |
the reduced value type |
| Name | Type | Description |
|---|---|---|
a |
Reduceable<A, B> |
the reducer |
mod |
B |
the starting reduced value |
the unary function. This function takes a Sequence.T<A> and reduces it to B
▸ filterReduce<A, B>(a, mod): B
Filters and reduce a Sequence.T<A> to B
Important The filter is applied before the reduce.
Example
import { Functors, Sequence, Num } from 'tiinvo'
const s = Sequence.make(1, 2, 3, 4, 5)
const f: Functors.FilterReduceableModule<number, number> = {
default: 0,
filter: Num.isEven,
reduce: Num.add,
}
Sequence.filterReduce(s, f) // 6
Since
4.0.0
| Name | Description |
|---|---|
A |
the sequence’s element type |
B |
the reduced value type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the sequence |
mod |
FilterReduceableModule<A, B> |
the filter and reduce module functor |
B
the reduced value
▸ filterReduce<A, B>(a): Unary<T<A>, B>
Returns a unary function which filters and reduce a Sequence.T<A> to B
Important The filter is applied before the reduce.
Example
import { Functors, Sequence, Num } from 'tiinvo'
const fr = Sequence.filterReduce({
default: 0,
filter: Num.isEven,
reduce: Num.add,
})
fr(Sequence.make(1, 2, 3, 4, 5)) // 6
Since
4.0.0
| Name | Description |
|---|---|
A |
the sequence’s element type |
B |
the reduced value type |
| Name | Type | Description |
|---|---|---|
a |
FilterReduceableModule<A, B> |
the filter and reduce module functor |
the unary function which takes a sequence the filters and reduce it to B
▸ filterMap<A, B>(a, f): T<B>
Filters and maps a Sequence.T<A> to a Sequence.T<B> using the FilterMappableModule<A, B> functor.
Important The filter is applied before the map.
Example
import { Functors, Sequence, Num } from 'tiinvo'
const f: Functors.FilterMappableModule<number, string | Error> = {
filter: Num.isOdd,
map: Num.toBin,
}
const s = Sequence.make(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
const m = Sequence.filterMap(f);
Sequence.filterMap(s, f) // ["0b1", "0b11", "0b101", "0b111", "0b1001"]
Since
4.0.0
| Name | Description |
|---|---|
A |
the sequence’s element type |
B |
the mapped sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the sequence |
f |
FilterMappableModule<A, B> |
the filterable and mappable functor |
T<B>
the filtered and mapped sequence
▸ filterMap<A, B>(a): Unary<T<A>, T<B>>
Returns a unary function which filters and maps a Sequence.T<A> to a Sequence.T<B>
using the FilterMappableModule<A, B> functor.
Important The filter is applied before the map.
Example
import { Functors, Sequence, Num } from 'tiinvo'
const m = Sequence.filterMap({
filter: Num.isOdd,
map: Num.toBin,
});
m(Sequence.make(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) // ["0b1", "0b11", "0b101", "0b111", "0b1001"]
Since
4.0.0
| Name | Description |
|---|---|
A |
the sequence’s element type |
B |
the mapped sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
FilterMappableModule<A, B> |
the filterable and mappable functor |
the unary function which filters and maps the input sequence T<A> to T<B>
▸ filter<A>(a, f): T<A>
Filters a Sequence.T<A> with a specified Filterable<a>
Example
import { Sequence, Num } from 'tiinvo'
const s = Sequence.make(10, 20, 30, 40)
Sequence.filter(s, Num.gt(20)) // Sequence.make(30, 40)
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the sequence |
f |
Filterable<A> |
the filterable functor |
T<A>
the filtered sequence
▸ filter<A>(a): Unary<T<A>, T<A>>
Returns a unary function which filters a Sequence.T<A> with a specified Filterable<a>
Example
import { Sequence, Num } from 'tiinvo'
const s = Sequence.make(10, 20, 30, 40)
Sequence.filter(Num.gt(20))(s) // Sequence.make(30, 40)
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
Filterable<A> |
the filterable functor |
the unary function which takes a sequence and filters it with a
▸ filterReduce<A, B>(a, mod): B
Filters and reduce a Sequence.T<A> to B
Important The filter is applied before the reduce.
Example
import { Functors, Sequence, Num } from 'tiinvo'
const s = Sequence.make(1, 2, 3, 4, 5)
const f: Functors.FilterReduceableModule<number, number> = {
default: 0,
filter: Num.isEven,
reduce: Num.add,
}
Sequence.filterReduce(s, f) // 6
Since
4.0.0
| Name | Description |
|---|---|
A |
the sequence’s element type |
B |
the reduced value type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the sequence |
mod |
FilterReduceableModule<A, B> |
the filter and reduce module functor |
B
the reduced value
▸ filterReduce<A, B>(a): Unary<T<A>, B>
Returns a unary function which filters and reduce a Sequence.T<A> to B
Important The filter is applied before the reduce.
Example
import { Functors, Sequence, Num } from 'tiinvo'
const fr = Sequence.filterReduce({
default: 0,
filter: Num.isEven,
reduce: Num.add,
})
fr(Sequence.make(1, 2, 3, 4, 5)) // 6
Since
4.0.0
| Name | Description |
|---|---|
A |
the sequence’s element type |
B |
the reduced value type |
| Name | Type | Description |
|---|---|---|
a |
FilterReduceableModule<A, B> |
the filter and reduce module functor |
the unary function which takes a sequence the filters and reduce it to B
▸ filterMap<A, B>(a, f): T<B>
Filters and maps a Sequence.T<A> to a Sequence.T<B> using the FilterMappableModule<A, B> functor.
Important The filter is applied before the map.
Example
import { Functors, Sequence, Num } from 'tiinvo'
const f: Functors.FilterMappableModule<number, string | Error> = {
filter: Num.isOdd,
map: Num.toBin,
}
const s = Sequence.make(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
const m = Sequence.filterMap(f);
Sequence.filterMap(s, f) // ["0b1", "0b11", "0b101", "0b111", "0b1001"]
Since
4.0.0
| Name | Description |
|---|---|
A |
the sequence’s element type |
B |
the mapped sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the sequence |
f |
FilterMappableModule<A, B> |
the filterable and mappable functor |
T<B>
the filtered and mapped sequence
▸ filterMap<A, B>(a): Unary<T<A>, T<B>>
Returns a unary function which filters and maps a Sequence.T<A> to a Sequence.T<B>
using the FilterMappableModule<A, B> functor.
Important The filter is applied before the map.
Example
import { Functors, Sequence, Num } from 'tiinvo'
const m = Sequence.filterMap({
filter: Num.isOdd,
map: Num.toBin,
});
m(Sequence.make(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) // ["0b1", "0b11", "0b101", "0b111", "0b1001"]
Since
4.0.0
| Name | Description |
|---|---|
A |
the sequence’s element type |
B |
the mapped sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
FilterMappableModule<A, B> |
the filterable and mappable functor |
the unary function which filters and maps the input sequence T<A> to T<B>
▸ append<A>(a, b): T<A>
Adds an element to the end of the Sequence.T<A> without mutating the original one.
Example
import { Sequence } from 'tiinvo'
const s0 = Sequence.make(10, 20)
Sequence.append(s0, 30) // Sequence(10, 20, 30)
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the sequence |
b |
A |
the element to append |
T<A>
the new sequence
▸ append<A>(a): Unary<T<A>, T<A>>
Returns a unary function which adds an element to the end of the Sequence.T<A>
without mutating it.
Example
import { Sequence } from 'tiinvo'
const s0 = Sequence.make(10, 20)
Sequence.append(30)(s0) // Sequence(10, 20, 30)
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
A |
the element to append |
the unary function which appends a to an existing sequence
▸ concat<A, B>(a, b): T<A & B>
Concatenates two Sequence.T<A> and Sequence.T<B> and return a new Sequence.T<A & B>.
Example
import { Sequence } from 'tiinvo'
const s0 = Sequence.make(10, 20)
const s1 = Sequence.make(30, 40)
Sequence.concat(s0, s1) // Sequence(10, 20, 30, 40)
Since
4.0.0
| Name | Description |
|---|---|
A |
the first Sequence’s element type |
B |
the second Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the first sequence |
b |
T<B> |
the second sequence |
T<A & B>
the concatated sequence
▸ concat<A, B>(a): Unary<T<B>, T<A & B>>
Returns a unary function which concatenates two Sequence.T<A> and Sequence.T<B>
and return a new Sequence.T<A & B>.
Example
import { Sequence } from 'tiinvo'
const s0 = Sequence.make(10, 20)
const s1 = Sequence.make(30, 40)
Sequence.concat(s1)(s0) // Sequence(10, 20, 30, 40)
Since
4.0.0
| Name | Description |
|---|---|
A |
the first Sequence’s element type |
B |
the second Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the first sequence |
the unary function which concatenates b to a
▸ prepend<A>(a, b): T<A>
Adds an element to the start of the Sequence.T<A> without mutating the original one.
Example
import { Sequence } from 'tiinvo'
const s0 = Sequence.make(10, 20)
Sequence.prepend(s0, 30) // Sequence(30, 10, 20)
Sequence.prepend(30)(s0) // Sequence(30, 10, 20)
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the sequence |
b |
A |
the element to prepend |
T<A>
the new sequence with b prepended to a
▸ prepend<A>(a): Unary<T<A>, T<A>>
Returns a unary function which adds an element to the start of the Sequence.T<A>
without mutating the original one.
Example
import { Sequence } from 'tiinvo'
const s0 = Sequence.make(10, 20)
Sequence.prepend(30)(s0) // Sequence(30, 10, 20)
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
A |
the element to prepend |
the unary function which prepends a to b
▸ count<A>(a, p): number
Counts the number of elements that satisfy a given predicate
Example
import { Sequence, Num } from 'tiinvo'
const s = Sequence.make(10, 20, 30)
Sequence.count(s, Num.gt(10)) // 2
Sequence.count(s, Num.gt(20)) // 1
Sequence.count(s, Num.gt(50)) // 0
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the sequence |
p |
Filterable<A> |
the Filterable functor |
number
the number of elements which satisfy the predicate p
▸ count<A>(a): Unary<T<A>, number>
Returns a unary function which counts the number of elements that satisfy a given predicate
Example
import { Sequence, Num } from 'tiinvo'
const gt10 = Sequence.count(Num.gt(10));
gt10(Sequence.make(10, 20, 30)) // 2
gt10(Sequence.make(5, 7, 9)) // 0
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
Filterable<A> |
the Filterable functor |
the unary function which counts how many elements in b satisfy the predicate p
▸ first<A>(t): T<A>
Gets a Sequence.T<A>’s first element.
Returns Option.None if none is found.
Example
import { Sequence } from 'tiinvo'
const s0 = Sequence.make(10, 20, 30)
const s1 = Sequence.make()
Sequence.first(s0) // 10
Sequence.first(s1) // null
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
t |
T<A> |
the sequence |
T<A>
the first element of the sequence:
Option.Some<A> if the sequence has at least one elementOption.None otherwise▸ get<A>(a, i): T<A>
Gets an element at a specific index.
Example
import { Sequence } from 'tiinvo'
const s = Sequence.make('hello', 'world')
Sequence.get(s, 0) // 'hello'
Sequence.get(s, 9) // RangeError(`Index out of bounds 9 for length 2`);
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the sequence |
i |
number |
the index of the element |
T<A>
Result.Ok<A> if i is in boundResult.Err if i is out of bound or negative▸ get<A>(a): Unary<T<A>, T<A>>
Returns a unary function which gets an element at a specific index.
Example
import { Sequence } from 'tiinvo'
const s = Sequence.make('hello', 'world')
const get0 = Sequence.get(0);
const get9 = Sequence.get(9);
get0(s) // 'hello'
get9(s) // RangeError(`Index out of bounds 9 for length 2`);
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
number |
the index of the element |
the unary function which accepts a Sequence.T<A> and returns
Result.Ok<A> if i is in boundResult.Err if i is out of bound or negative▸ last<A>(t): T<A>
Gets a Sequence.T<A>’s last element if any.
Example
import { Sequence } from 'tiinvo'
const s0 = Sequence.make(10, 20, 30)
const s1 = Sequence.make()
Sequence.last(s0) // 30
Sequence.last(s1) // null
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
t |
T<A> |
the sequence |
T<A>
Option.Some<A> if the sequence is not emptyOption.None otherwise▸ length<A>(t): number
Gets the length of a Sequence.T<A>
Example
import { Sequence } from 'tiinvo'
const s = Sequence.make(1, 2, 3)
Sequence.length(s) // 3
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
t |
T<A> |
the sequence |
number
the Sequence’s length
▸ values<A>(t): Record<number, A>
Gets values of a Sequence.T<A> as an immutable indexed object.
Example
import { Sequence } from 'tiinvo'
const s = Sequence.make('hello', 'world')
Sequence.values(s) // { 0: 'hello', 1: 'world' }
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
t |
T<A> |
the sequence |
Record<number, A>
the sequence values as an immutable dictionary
▸ empty<A>(t): boolean
Returns true if the sequence is empty.
Example
import { Sequence } from 'tiinvo'
const s = Sequence.make()
const s1 = Sequence.make(10)
Sequence.empty(s) // true
Sequence.empty(s1) // false
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
t |
T<A> |
the sequence |
boolean
▸ populated<a>(t): boolean
Returns true if the sequence is populated.
Example
import { Sequence } from 'tiinvo'
const s = Sequence.make(10, 20, 30)
Sequence.populated(s) // true
Sequence.populated(Sequence.make()) // false
Since
4.0.0
| Name |
|---|
a |
| Name | Type | Description |
|---|---|---|
t |
T<a> |
the sequence |
boolean
▸ sort<A>(a, mod): T<A>
Sorts and returns a new Sequence.T<A> values with a Comparable<a> or ComparableModule<a> functor.
Example
import { Sequence, Num } from 'tiinvo'
const a = Sequence.make(5, 3, 1, 4, 2)
const b = Sequence.sort(a, Num)
Sequence.sort(a, Num) // Sequence.make(1, 2, 3, 4, 5)
Sequence.sort(b, Num.desc) // Sequence.make(5, 3, 1, 4, 2)
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the sequence |
mod |
Comparable<A> | ComparableModule<A> |
the Comparable functor or the Comparable module functor |
T<A>
the sorted sequence
▸ sort<A>(a): Unary<T<A>, T<A>>
Returns a unary function which sorts and returns a new Sequence.T<A> values
with a Comparable<a> or ComparableModule<a> functor.
Example
import { Sequence, Num } from 'tiinvo'
const asc = Sequence.sort(Num.asc)
const desc = Sequence.sort(Num.desc)
const s0 = Sequence.make(1, 2, 3)
const s1 = Sequence.make(6, 5, 4)
asc(s1) // Sequence.make(4, 5, 6)
desc(s0) // Sequence.make(3, 2, 1)
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
Comparable<A> | ComparableModule<A> |
the Comparable functor or the Comparable module functor |
the unary function which sorts the passed sequence
▸ toArray<A>(t): A[]
Converts a Sequence.T<A> to an array a[]
Example
import { Sequence } from 'tiinvo'
const s = Sequence.make(10, 20, 30)
Sequence.toArray(s) // [10, 20, 30]
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
t |
T<A> |
the sequence |
A[]
the array
▸ toJSON<a>(t): a[]
Serializes a Sequence.T<A> to json
Example
import { Sequence } from 'tiinvo'
Sequence.toJSON(Sequence.make(1, 2)) // { 0: 1, 1: 2 }
Since
4.0.0
| Name |
|---|
a |
| Name | Type | Description |
|---|---|---|
t |
T<a> |
the sequence |
a[]
the JSONised value
▸ toMap<A>(t): Map<string, A>
Serializes a Sequence.T<A> to a Map<number, a>
Example
import { Sequence } from 'tiinvo'
Sequence.toMap(Sequence.make(1, 2)) // Map([0, 1], [1, 2])
Since
4.0.0
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
t |
T<A> |
the sequence |
Map<string, A>
the Map
▸ toSet<A>(t): Set<A>
Converts a Sequence.T<A> to a Set Set<a>
Example
import { Sequence } from 'tiinvo'
const s = Sequence.make(10, 20, 30)
Sequence.toSet(s) // Set(10, 20, 30)
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
t |
T<A> |
the sequence |
Set<A>
the Set
▸ toString<A>(t): string
Stringifies a Sequence.T<A>
Example
import { Sequence } from 'tiinvo'
const s = Sequence.make(10, 20, 30)
Sequence.toString(s) // '10,20,30'
Since
4.0.0
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
t |
T<A> |
the sequence |
string
the string