tiinvo

tiinvo / Exports / Sequence

Namespace: Sequence

Table of contents

Type Aliases

Factories

Guardables

Comparables

Mappables

Filterables

Operators

Accessors

Predicates

Sortables

Serializables

Type Aliases

T

Ƭ 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.

Type parameters

Name
A

Defined in

src/Sequence.ts:13

Factories

fromString

fromString<A>(x): T<T<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

Type parameters

Name Type Description
A unknown the Sequence’s expected element type

Parameters

Name Type Description
x string the string

Returns

T<T<A>>

Defined in

src/Sequence.ts:44


make

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

Type parameters

Name Description
A the type

Parameters

Name Type Description
v A[] the array of initial values

Returns

T<A>

the Sequence.T<A>

Defined in

src/Sequence.ts:73

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

Type parameters

Name Description
A the type

Parameters

Name Type Description
...v A[] the list of initial values

Returns

T<A>

the Sequence.T<A>

Defined in

src/Sequence.ts:91

Guardables

guard

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

Parameters

Name Type Description
x unknown the value to guard

Returns

x is T<unknown>

Defined in

src/Sequence.ts:161


guardOf

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

Type parameters

Name
A

Parameters

Name Type Description
g Guardable<A> the guard

Returns

fn

the new guard which returns

▸ (x): x is T<A>

Parameters
Name Type
x unknown
Returns

x is T<A>

Defined in

src/Sequence.ts:187

Comparables

cmp

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
mod ComparableModule<A> the comparable functor module
a T<A> the first sequence
b T<A> the last sequence

Returns

ComparableResult

the comparison result Functors.ComparableResult

Defined in

src/Sequence.ts:226

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
mod Comparable<A> the comparable functor
a T<A> the first sequence
b T<A> the last sequence

Returns

ComparableResult

the comparison result Functors.ComparableResult

Defined in

src/Sequence.ts:260

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
mod ComparableModule<A> the comparable functor module
a T<A> the first sequence

Returns

Unary<T<A>, ComparableResult>

the unary function

Defined in

src/Sequence.ts:285

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
mod Comparable<A> the comparable functor
a T<A> the first sequence

Returns

Unary<T<A>, ComparableResult>

the unary function

Defined in

src/Sequence.ts:310

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
mod ComparableModule<A> the comparable functor module

Returns

Binary<T<A>, T<A>, ComparableResult>

the binary function

Defined in

src/Sequence.ts:334

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
mod Comparable<A> the comparable functor

Returns

Binary<T<A>, T<A>, ComparableResult>

the binary function

Defined in

src/Sequence.ts:358


eq

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
mod EquatableModule<A> the equatable module functor
a T<A> the first Sequence
b T<A> the last Sequence

Returns

boolean

Defined in

src/Sequence.ts:401

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
mod Equatable<A> the equatable functor
a T<A> the first Sequence
b T<A> the last Sequence

Returns

boolean

Defined in

src/Sequence.ts:428

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
mod EquatableModule<A> the equatable module functor
a T<A> the first Sequence

Returns

Unary<T<A>, boolean>

the unary function which checks and returns

Defined in

src/Sequence.ts:456

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
mod Equatable<A> the equatable functor
a T<A> the first Sequence

Returns

Unary<T<A>, boolean>

the unary function which checks and returns

Defined in

src/Sequence.ts:484

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
mod EquatableModule<A> the equatable module functor

Returns

Binary<T<A>, T<A>, boolean>

the binary function which checks and returns

Defined in

src/Sequence.ts:511

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
mod Equatable<A> the equatable functor

Returns

Binary<T<A>, T<A>, boolean>

the binary function which checks and returns

Defined in

src/Sequence.ts:538

Mappables

map

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

Type parameters

Name Description
A the sequence’s element type
B the mapped sequence’s element type

Parameters

Name Type Description
a T<A> the sequence
m Mappable<A, B> the mappable functor

Returns

T<B>

the mapped sequence

Defined in

src/Sequence.ts:580

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

Type parameters

Name Description
A the sequence’s element type
B the mapped sequence’s element type

Parameters

Name Type Description
a Mappable<A, B> the sequence

Returns

Unary<T<A>, T<B>>

the unary function which maps Sequence.T to Sequence.T<B>

Defined in

src/Sequence.ts:601


reduce

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

Type parameters

Name Description
A the sequence’s element type
B the reduced value type

Parameters

Name Type Description
a T<A> the sequence
mod Reduceable<A, B> the reducer functor
s B the starting reduced value

Returns

B

the reduced value

Defined in

src/Sequence.ts:637

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

Type parameters

Name Description
A the sequence’s element type
B the reduced value type

Parameters

Name Type Description
a Reduceable<A, B> the reducer
mod B the starting reduced value

Returns

Unary<T<A>, B>

the unary function. This function takes a Sequence.T<A> and reduces it to B

Defined in

src/Sequence.ts:659


filterReduce

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

Type parameters

Name Description
A the sequence’s element type
B the reduced value type

Parameters

Name Type Description
a T<A> the sequence
mod FilterReduceableModule<A, B> the filter and reduce module functor

Returns

B

the reduced value

Defined in

src/Sequence.ts:754

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

Type parameters

Name Description
A the sequence’s element type
B the reduced value type

Parameters

Name Type Description
a FilterReduceableModule<A, B> the filter and reduce module functor

Returns

Unary<T<A>, B>

the unary function which takes a sequence the filters and reduce it to B

Defined in

src/Sequence.ts:782


filterMap

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

Type parameters

Name Description
A the sequence’s element type
B the mapped sequence’s element type

Parameters

Name Type Description
a T<A> the sequence
f FilterMappableModule<A, B> the filterable and mappable functor

Returns

T<B>

the filtered and mapped sequence

Defined in

src/Sequence.ts:838

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

Type parameters

Name Description
A the sequence’s element type
B the mapped sequence’s element type

Parameters

Name Type Description
a FilterMappableModule<A, B> the filterable and mappable functor

Returns

Unary<T<A>, T<B>>

the unary function which filters and maps the input sequence T<A> to T<B>

Defined in

src/Sequence.ts:866

Filterables

filter

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
a T<A> the sequence
f Filterable<A> the filterable functor

Returns

T<A>

the filtered sequence

Defined in

src/Sequence.ts:694

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
a Filterable<A> the filterable functor

Returns

Unary<T<A>, T<A>>

the unary function which takes a sequence and filters it with a

Defined in

src/Sequence.ts:714


filterReduce

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

Type parameters

Name Description
A the sequence’s element type
B the reduced value type

Parameters

Name Type Description
a T<A> the sequence
mod FilterReduceableModule<A, B> the filter and reduce module functor

Returns

B

the reduced value

Defined in

src/Sequence.ts:754

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

Type parameters

Name Description
A the sequence’s element type
B the reduced value type

Parameters

Name Type Description
a FilterReduceableModule<A, B> the filter and reduce module functor

Returns

Unary<T<A>, B>

the unary function which takes a sequence the filters and reduce it to B

Defined in

src/Sequence.ts:782


filterMap

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

Type parameters

Name Description
A the sequence’s element type
B the mapped sequence’s element type

Parameters

Name Type Description
a T<A> the sequence
f FilterMappableModule<A, B> the filterable and mappable functor

Returns

T<B>

the filtered and mapped sequence

Defined in

src/Sequence.ts:838

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

Type parameters

Name Description
A the sequence’s element type
B the mapped sequence’s element type

Parameters

Name Type Description
a FilterMappableModule<A, B> the filterable and mappable functor

Returns

Unary<T<A>, T<B>>

the unary function which filters and maps the input sequence T<A> to T<B>

Defined in

src/Sequence.ts:866

Operators

append

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
a T<A> the sequence
b A the element to append

Returns

T<A>

the new sequence

Defined in

src/Sequence.ts:916

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
a A the element to append

Returns

Unary<T<A>, T<A>>

the unary function which appends a to an existing sequence

Defined in

src/Sequence.ts:937


concat

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

Type parameters

Name Description
A the first Sequence’s element type
B the second Sequence’s element type

Parameters

Name Type Description
a T<A> the first sequence
b T<B> the second sequence

Returns

T<A & B>

the concatated sequence

Defined in

src/Sequence.ts:970

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

Type parameters

Name Description
A the first Sequence’s element type
B the second Sequence’s element type

Parameters

Name Type Description
a T<A> the first sequence

Returns

Unary<T<B>, T<A & B>>

the unary function which concatenates b to a

Defined in

src/Sequence.ts:993


prepend

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
a T<A> the sequence
b A the element to prepend

Returns

T<A>

the new sequence with b prepended to a

Defined in

src/Sequence.ts:1025

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
a A the element to prepend

Returns

Unary<T<A>, T<A>>

the unary function which prepends a to b

Defined in

src/Sequence.ts:1046

Accessors

count

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
a T<A> the sequence
p Filterable<A> the Filterable functor

Returns

number

the number of elements which satisfy the predicate p

Defined in

src/Sequence.ts:1083

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
a Filterable<A> the Filterable functor

Returns

Unary<T<A>, number>

the unary function which counts how many elements in b satisfy the predicate p

Defined in

src/Sequence.ts:1105


first

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
t T<A> the sequence

Returns

T<A>

the first element of the sequence:

Defined in

src/Sequence.ts:1141


get

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
a T<A> the sequence
i number the index of the element

Returns

T<A>

Defined in

src/Sequence.ts:1170

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
a number the index of the element

Returns

Unary<T<A>, T<A>>

the unary function which accepts a Sequence.T<A> and returns

Defined in

src/Sequence.ts:1195


last

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
t T<A> the sequence

Returns

T<A>

Defined in

src/Sequence.ts:1241


length

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
t T<A> the sequence

Returns

number

the Sequence’s length

Defined in

src/Sequence.ts:1266


values

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
t T<A> the sequence

Returns

Record<number, A>

the sequence values as an immutable dictionary

Defined in

src/Sequence.ts:1287

Predicates

empty

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
t T<A> the sequence

Returns

boolean

Defined in

src/Sequence.ts:1316


populated

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

Type parameters

Name
a

Parameters

Name Type Description
t T<a> the sequence

Returns

boolean

Defined in

src/Sequence.ts:1340

Sortables

sort

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
a T<A> the sequence
mod Comparable<A> | ComparableModule<A> the Comparable functor or the Comparable module functor

Returns

T<A>

the sorted sequence

Defined in

src/Sequence.ts:1368

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
a Comparable<A> | ComparableModule<A> the Comparable functor or the Comparable module functor

Returns

Unary<T<A>, T<A>>

the unary function which sorts the passed sequence

Defined in

src/Sequence.ts:1394

Serializables

toArray

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
t T<A> the sequence

Returns

A[]

the array

Defined in

src/Sequence.ts:1430


toJSON

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

Type parameters

Name
a

Parameters

Name Type Description
t T<a> the sequence

Returns

a[]

the JSONised value

Defined in

src/Sequence.ts:1449


toMap

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
t T<A> the sequence

Returns

Map<string, A>

the Map

Defined in

src/Sequence.ts:1469


toSet

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
t T<A> the sequence

Returns

Set<A>

the Set

Defined in

src/Sequence.ts:1490


toString

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

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
t T<A> the sequence

Returns

string

the string

Defined in

src/Sequence.ts:1511