tiinvo

tiinvo / Exports / TypedSequence

Namespace: TypedSequence

Table of contents

Type Aliases

Functions

Guardables

Sortables

comparables

Serializables

Type Aliases

T

Ƭ T<A>: T<A> & { [guardsymbol]: Guardable<A> }

The typed version of a Sequence.t<A>.

Type parameters

Name
A

Defined in

src/TypedSequence.ts:10

Functions

make

make<A>(g, ...values): T<A>

Creates a TypedSequence.t<A> starting from a Guardable<A> functor

You can add initial values as arguments.

If an argument does pass the guard check, the function will throw a TypeError

Example

import { TypedSequence, Num } from 'tiinvo'

for (const x of TypedSequence.make(Num.guard, 10, 20, 30)) {
   console.log(x)
}
// 10
// 20
// 30

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type
g Guardable<A>
...values A[]

Returns

T<A>

Defined in

src/TypedSequence.ts:38

make<A>(g, ...values): T<A>

Creates a TypedSequence.t<A> starting from a GuardableModule<A>

You can add initial values as arguments.

If an argument does pass the guard check, the function will throw a TypeError

Example

import { TypedSequence, Num } from 'tiinvo'

for (const x of TypedSequence.make(Num, 10, 20, 30)) {
   console.log(x)
}
// 10
// 20
// 30

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type
g GuardableModule<A>
...values A[]

Returns

T<A>

Defined in

src/TypedSequence.ts:61


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 { TypedSequence, Num } from 'tiinvo'

const s0 = TypedSequence.make(Num, 10, 20)

TypedSequence.append(s0, 30)       // TypedSequence(10, 20, 30)

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type Description
a T<A> the TypedSequence
b A the value to append

Returns

T<A>

Defined in

src/TypedSequence.ts:142

append<A>(a): Unary<T<A>, T<A>>

Returns a unary function which adds an element a to the end of the Sequence.t<A> without mutating the original one.

Example

import { TypedSequence, Num } from 'tiinvo'

const s0 = TypedSequence.make(Num, 10, 20)

TypedSequence.append(30)(s0)       // TypedSequence(10, 20, 30)

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type Description
a A the value to append

Returns

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

the unary function

Defined in

src/TypedSequence.ts:161


concat

concat<a>(a, b): a

Concatenates two TypedSequence.t<A> and TypedSequence.t<b> and return a new TypedSequence.t<A>.

Example

import { TypedSequence, Num } from 'tiinvo'

const s0 = TypedSequence.make(Num, 10, 20)
const s1 = TypedSequence.make(Num, 30, 40)

TypedSequence.concat(s0, s1)       // TypedSequence(10, 20, 30, 40)

Since

4.0.0

Type parameters

Name Type Description
a extends Iterable<any, a> & { [indexer]: () => Readonly<Record<number, any>> ; [iterator]: () => Iterator<any, any, undefined> } & { [guardsymbol]: Guardable<any> } the first TypedSequence

Parameters

Name Type Description
a a the last TypedSequence
b a -

Returns

a

the concatenated TypedSequence

Defined in

src/TypedSequence.ts:196

concat<a>(a): Unary<a, a>

Returns a unary function which concatenates two TypedSequence.t<A> and TypedSequence.t<b> and return a new TypedSequence.t<A>.

Example

import { TypedSequence, Num } from 'tiinvo'

const s0 = TypedSequence.make(Num, 10, 20)
const s1 = TypedSequence.make(Num, 30, 40)

TypedSequence.concat(s1)(s0)       // TypedSequence(10, 20, 30, 40)

Since

4.0.0

Type parameters

Name Type Description
a extends Iterable<any, a> & { [indexer]: () => Readonly<Record<number, any>> ; [iterator]: () => Iterator<any, any, undefined> } & { [guardsymbol]: Guardable<any> } the first TypedSequence

Parameters

Name Type Description
a a the last TypedSequence

Returns

Unary<a, a>

the concatenated TypedSequence

Defined in

src/TypedSequence.ts:217


prepend

prepend<A>(a, b): T<A>

Adds an element to the start of the TypedSequence.t<A> without mutating the original one.

Example

import { TypedSequence, Num } from 'tiinvo'

const s0 = TypedSequence.make(Num, 10, 20)

TypedSequence.prepend(s0, 30)       // TypedSequence.make(Num, 30, 10, 20)
TypedSequence.prepend(30)(s0)       // TypedSequence.make(Num, 30, 10, 20)

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type Description
a T<A> the TypedSequence
b A the value to prepend

Returns

T<A>

the new TypedSequence

Defined in

src/TypedSequence.ts:247

prepend<A>(a): Unary<T<A>, T<A>>

Returns a unary function which adds an element to the start of the TypedSequence.t<A> without mutating the original one.

Example

import { TypedSequence, Num } from 'tiinvo'

const s0 = TypedSequence.make(Num, 10, 20)

TypedSequence.prepend(30)(s0)       // TypedSequence.make(Num, 30, 10, 20)

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type Description
a A the value

Returns

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

the unary function

Defined in

src/TypedSequence.ts:266


count

count<A>(a, p): number

Counts the number of elements that satisfy a given predicate

Example

import { TypedSequence, Num } from 'tiinvo'

const s = TypedSequence.make(Num, 10, 20, 30)

TypedSequence.count(s, Num.gt(10))   // 2
TypedSequence.count(Num.gt(10))(s)   // 2

Since

4.0.0

Type parameters

Name
A

Parameters

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

Returns

number

the counted elements

Defined in

src/Sequence.ts:1083

count<A>(a): Unary<T<A>, number>

Counts the number of elements that satisfy a given predicate

Example

import { TypedSequence, Num } from 'tiinvo'

const s = TypedSequence.make(Num, 10, 20, 30)

TypedSequence.count(s, Num.gt(10))   // 2
TypedSequence.count(Num.gt(10))(s)   // 2

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type Description
a Filterable<A> the sequence

Returns

Unary<T<A>, number>

the counted elements

Defined in

src/Sequence.ts:1105


get

get<A>(a, i): T<A>

Example

import { TypedSequence, Str } from 'tiinvo'

const s = TypedSequence.make(Str, 'hello', 'world')

TypedSequence.get(s, 0)       // 'hello'
TypedSequence.get(s, 9)       // throws RangeError

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type
a T<A>
i number

Returns

T<A>

Defined in

src/Sequence.ts:1170

get<A>(a): Unary<T<A>, T<A>>

Example

import { TypedSequence, Str } from 'tiinvo'

const s = TypedSequence.make(Str, 'hello', 'world')

TypedSequence.get(s, 0)       // 'hello'
TypedSequence.get(s, 9)       // throws RangeError

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type
a number

Returns

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

Defined in

src/Sequence.ts:1195


first

first<A>(t): T<A>

Gets the first element of a TypedSequence.

Returns Option.None if none is found.

Example

import { TypedSequence, Num } from 'tiinvo'

const s0 = TypedSequence.make(Num, 10, 20, 30)
const s1 = TypedSequence.make(Num)

TypedSequence.first(s0)       // 10
TypedSequence.first(s1)       // null

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type
t T<A>

Returns

T<A>

Defined in

src/Sequence.ts:1141


last

last<A>(t): T<A>

Gets a Sequence.t’s last element.

Returns Option.None if none is found.

Example

import { TypedSequence, Num } from 'tiinvo'

const s0 = TypedSequence.make(Num, 10, 20, 30)
const s1 = TypedSequence.make(Num)

TypedSequence.last(s0)       // 30
TypedSequence.last(s1)       // null

@since 4.0.0

#### Type parameters

| Name |
| :------ |
| `A` |

#### Parameters

| Name | Type |
| :------ | :------ |
| `t` | [`T`](/tiinvo/modules/Sequence.html#t)<`A`\> |

#### Returns

[`T`](/tiinvo/modules/Opt.html#t)<`A`\>

#### Defined in

[src/Sequence.ts:1241](https://github.com/OctoD/tiinvo/blob/5743591/src/Sequence.ts#L1241)

___

### length

▸ **length**<`A`\>(`t`): `number`

Gets the length of a `TypedSequence.t<A>`

**`Example`**

```ts
import { TypedSequence, Num } from 'tiinvo'

const s = TypedSequence.make(Num, 1, 2, 3)

TypedSequence.length(s)           // 3

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type
t T<A>

Returns

number

Defined in

src/Sequence.ts:1266


values

values<A>(t): Record<number, A>

Gets values of a TypedSequence.t<A> as an immutable indexed object.

Example

import { TypedSequence, Str } from 'tiinvo'

const s = TypedSequence.make(Str, 'hello', 'world')

TypedSequence.values(s)       // { 0: 'hello', 1: 'world' }

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type
t T<A>

Returns

Record<number, A>

Defined in

src/Sequence.ts:1287


empty

empty<A>(t): boolean

Returns true if the sorted list is empty.

Example

import { TypedSequence, Num } from 'tiinvo'

const s = TypedSequence.make(Num)
const s1 = TypedSequence.make(Num, 10)

TypedSequence.empty(s)                // true
TypedSequence.empty(s1)               // false

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type
t T<A>

Returns

boolean

Defined in

src/Sequence.ts:1316


populated

populated<a>(t): boolean

Returns true if the sorted list is populated.

Example

import { TypedSequence, Num } from 'tiinvo'

const s = TypedSequence.make(Num, 10, 20, 30)

TypedSequence.populated(s)                      // true
TypedSequence.populated(TypedSequence.make(Num))   // false

Since

4.0.0

Type parameters

Name
a

Parameters

Name Type
t T<a>

Returns

boolean

Defined in

src/Sequence.ts:1340

Guardables

guard

guard(x): x is T<unknown>

Checks if the parameter x is a TypedSequence.t<unknown>

Example

import { TypedSequence, Sequence, Num } from 'tiinvo'

const a = TypedSequence.make(Num)
const b = Sequence.make()

TypedSequence.guard(a)     // true
TypedSequence.guard(b)     // false

Since

4.0.0

Parameters

Name Type Description
x unknown the guarded value

Returns

x is T<unknown>

Defined in

src/TypedSequence.ts:119

Sortables

sort

sort<A>(a, mod): T<A>

Sorts and returns a new TypedSequence.t<A> values with a Comparable<A> or ComparableModule<A> functor.

Example

import { TypedSequence, Num } from 'tiinvo'

const a = TypedSequence.make(Num, 5, 3, 1, 4, 2)
const b = TypedSequence.sort(a, Num)

b          // TypedSequence.make(Num, 1, 2, 3, 4, 5)

Since

4.0.0

Type parameters

Name Description
A the sequence type

Parameters

Name Type Description
a T<A> the sequence
mod Comparable<A> | ComparableModule<A> the Comparable used to sort the sequence

Returns

T<A>

the sorted sequence

Defined in

src/TypedSequence.ts:304

sort<A>(a): Unary<T<A>, T<A>>

Returns a unary function which sorts and returns a new TypedSequence.t<A> values with a Comparable<A> or ComparableModule<A> functor.

Example

import { TypedSequence, Num } from 'tiinvo'

const sort = TypedSequence.sort(Num)

const a = TypedSequence.make(Num, 5, 3, 1, 4, 2)
const b = sort(a)

b          // TypedSequence.make(Num, 1, 2, 3, 4, 5)

Since

4.0.0

Type parameters

Name Description
A the sequence type

Parameters

Name Type Description
a Comparable<A> | ComparableModule<A> the sequence

Returns

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

the sorting unary function

Defined in

src/TypedSequence.ts:328

comparables

cmp

cmp<A>(cmp, a, b): ComparableResult

Compares two TypedSequence.t<A> values with a Comparable<A> or ComparableModule<A> functor.

Example

import { TypedSequence, Num } from 'tiinvo'

const s0 = TypedSequence.make(Num, 1, 2, 3)
const s1 = TypedSequence.make(Num, 1, 2, 3)

TypedSequence.cmp(Num, s0, s1)       // 0
TypedSequence.cmp(Num)(s0, s1)       // 0
TypedSequence.cmp(Num, s0)(s1)       // 0
TypedSequence.cmp(Num)(s0)(s1)       // 0

Since

4.0.0

Type parameters

Name Description
A the sequence’s element type

Parameters

Name Type Description
cmp Comparable<A> | ComparableModule<A> the Comparable<A> or ComparableModule<A> functor
a T<A> the first sequence
b T<A> the second sequence

Returns

ComparableResult

the comparison result

Defined in

src/TypedSequence.ts:496

cmp<A>(cmp, a): Unary<T<A>, ComparableResult>

Returns a comparer function that compares two TypedSequence.t<A> values with a Comparable<A> or ComparableModule<A> functor.

Example

import { TypedSequence, Num } from 'tiinvo'

const s0 = TypedSequence.make(Num, 1, 2, 3)
const s1 = TypedSequence.make(Num, 1, 2, 3)

const c = TypedSequence.cmp(Num, s0)

c(s1)       // 0

Since

4.0.0

Type parameters

Name Description
A the sequence’s element type

Parameters

Name Type Description
cmp Comparable<A> | ComparableModule<A> the Comparable<A> or ComparableModule<A> functor
a T<A> the first sequence

Returns

Unary<T<A>, ComparableResult>

the comparer function

Defined in

src/TypedSequence.ts:523

cmp<A>(cmp): Binary<T<A>, T<A>, ComparableResult>

Returns a comparer function that compares two TypedSequence.t<A> values with a Comparable<A> or ComparableModule<A> functor.

Example

import { TypedSequence, Num } from 'tiinvo'

const s0 = TypedSequence.make(Num, 1, 2, 3)
const s1 = TypedSequence.make(Num, 1, 2, 3)

const c = TypedSequence.cmp(Num)

c(s0, s1)       // 0

Since

4.0.0

Type parameters

Name Description
A the sequence’s element type

Parameters

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

Returns

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

the comparer function

Defined in

src/TypedSequence.ts:549


eq

eq<A>(eq, a, b): boolean

Checks if two TypedSequence.t<A> values are equal with an Equatable<A> or EquatableModule<A> functor.

Example

import { TypedSequence, Num } from 'tiinvo'

const s0 = TypedSequence.make(Num, 1, 2, 3)
const s1 = TypedSequence.make(Num, 1, 2, 3)

TypedSequence.eq(Num, s0, s1)       // true

Since

4.0.0

Type parameters

Name Description
A the sequence’s element type

Parameters

Name Type Description
eq Equatable<A> | EquatableModule<A> the Equatable<A> or EquatableModule<A> functor
a T<A> the first sequence
b T<A> the second sequence

Returns

boolean

true if the sequences are equal, false otherwise

Defined in

src/TypedSequence.ts:621

eq<A>(eq, a): Unary<T<A>, boolean>

Returns a comparer function that checks if two TypedSequence.t<A> values are equal with an Equatable<A> or EquatableModule<A> functor.

Example

import { TypedSequence, Num } from 'tiinvo'

const s2 = TypedSequence.make(Num, 1, 2, 3)
const s3 = TypedSequence.make(Num, 1, 2, 3)

const c = TypedSequence.eq(Num, s0)

c(s1)       // true

Since

4.0.0

Type parameters

Name Description
A the sequence’s element type

Parameters

Name Type Description
eq Equatable<A> | EquatableModule<A> the Equatable<A> or EquatableModule<A> functor
a T<A> the first sequence

Returns

Unary<T<A>, boolean>

the comparer function

Defined in

src/TypedSequence.ts:648

eq<A>(eq): Binary<T<A>, T<A>, boolean>

Returns a comparer function that checks if two TypedSequence.t<A> values are equal with an Equatable<A> or EquatableModule<A> functor.

Example

import { TypedSequence, Num } from 'tiinvo'

const s0 = TypedSequence.make(Num, 1, 2, 3)
const s1 = TypedSequence.make(Num, 1, 2, 3)

const c = TypedSequence.eq(Num)

c(s0, s1)       // true

Since

4.0.0

Type parameters

Name Description
A the sequence’s element type

Parameters

Name Type Description
eq Equatable<A> | EquatableModule<A> the Equatable<A> or EquatableModule<A> functor

Returns

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

the comparer function

Defined in

src/TypedSequence.ts:674

Serializables

toArray

toArray<A>(t): A[]

Converts a TypedSequence.t<A> to an array of a[]

Example

import { TypedSequence, Num } from 'tiinvo'

const sl = TypedSequence.make(Num, 3, 2, 1)

TypedSequence.toArray(sl)       // [3, 2, 1]

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type
t T<A>

Returns

A[]

the array

Defined in

src/Sequence.ts:1430


toJSON

toJSON<a>(t): a[]

Converts a TypedSequence.t<A> to a jsonizable value

Example

import { TypedSequence, Num } from 'tiinvo'

const sl = TypedSequence.make(Num, 3, 2, 1)

TypedSequence.toJSON(sl)       // [3, 2, 1]

Since

4.0.0

Type parameters

Name
a

Parameters

Name Type
t T<a>

Returns

a[]

the JSON

Defined in

src/Sequence.ts:1449


toMap

toMap<A>(t): Map<string, A>

Converts a TypedSequence.t<A> to a set of Set<A>

Example

import { TypedSequence, Num } from 'tiinvo'

const sl = TypedSequence.make(Num, 3, 2, 1)

TypedSequence.toMap(sl)      // Map([0, 3], [1, 2], [2, 1])

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type
t T<A>

Returns

Map<string, A>

the Map

Defined in

src/Sequence.ts:1469


toSet

toSet<A>(t): Set<A>

Converts a TypedSequence.t<A> to a set of Set<A>

Example

import { TypedSequence, Num } from 'tiinvo'

const sl = TypedSequence.make(Num, 3, 2, 1)

TypedSequence.toSet(sl)      // Set(3, 2, 1)

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type
t T<A>

Returns

Set<A>

the Set

Defined in

src/Sequence.ts:1490


toString

toString<A>(t): string

Converts a TypedSequence.t<A> to a string

Example

import { TypedSequence, Num } from 'tiinvo'

const sl = TypedSequence.make(Num, 3, 2, 1)

TypedSequence.toString(sl)       // "3,2,1"

Since

4.0.0

Type parameters

Name
A

Parameters

Name Type
t T<A>

Returns

string

Defined in

src/Sequence.ts:1511