tiinvo

tiinvo / Exports / SortedSequence

Namespace: SortedSequence

Table of contents

Type Aliases

Factories

Guards

Guardables

Comparables

Mappables

Operables

Accessors

Functions

Predicates

Serializables

Type Aliases

T

Ƭ T<a>: T<a> & { [sortsymbol]: Comparable<a> }

A sorted sequence is a Sequence.t<a> which all elements stored in it are sorted by a Comparable<a> functor.

Type parameters

Name
a

Defined in

src/SortedSequence.ts:10

Factories

make

make<A>(mod, ...args): T<A>

Makes an immutable SortedSequence.T<A> from a Comparable<a> and (optionally) a list of arguments as initial values

Example

import { SortedSequence, Num, Str } from 'tiinvo'

const s0 = SortedSequence.make(Num.cmp, 10, 20, 30)         
const s1 = SortedSequence.make(Str.cmp, 'hello', 'world')

SortedSequence.guardOf(Num.guard)(s0)    // true
SortedSequence.guardOf(Num.guard)(s1)    // false
SortedSequence.guardOf(Str.guard)(s0)    // false
SortedSequence.guardOf(Str.guard)(s1)    // true

Since

4.0.0

Type parameters

Name Description
A element’s type

Parameters

Name Type Description
mod Comparable<A> the Comparable functor
...args A[] a list of initial values

Returns

T<A>

the SortedSequence

Defined in

src/SortedSequence.ts:40

make<A>(mod, ...args): T<A>

Makes an immutable SortedSequence.T<A> from a ComparableModule<a> and (optionally) a list of arguments as initial values

Example

import { SortedSequence, Num, Str } from 'tiinvo'

const s0 = SortedSequence.make(Num, 10, 20, 30)         
const s1 = SortedSequence.make(Str, 'hello', 'world')

SortedSequence.guardOf(Num.guard)(s0)    // true
SortedSequence.guardOf(Num.guard)(s1)    // false
SortedSequence.guardOf(Str.guard)(s0)    // false
SortedSequence.guardOf(Str.guard)(s1)    // true

Since

4.0.0

Type parameters

Name Description
A element’s type

Parameters

Name Type Description
mod ComparableModule<A> the Comparable module functor
...args A[] a list of initial values

Returns

T<A>

the SortedSequence

Defined in

src/SortedSequence.ts:65

Guards

guard

guard(x): x is T<unknown>

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

Example

import { SortedSequence, Str } from 'tiinvo'

const s = SortedSequence.make(Str)

SortedSequence.guard(s)         // true
SortedSequence.guard([])        // false

Since

4.0.0

Parameters

Name Type Description
x unknown the value to guard

Returns

x is T<unknown>

Defined in

src/SortedSequence.ts:101

Guardables

guardOf

guardOf<A>(g, x): x is T<A>

Checks if the parameter x is a SortedSequence.T<A> using a Guardable<A> functor.

Example

import { SortedSequence, Num, Str } from 'tiinvo'

const s0 = SortedSequence.make(Num, 1, 2)
const s1 = SortedSequence.make(Str, 'hello', 'world')

SortedSequence.guardOf(Str.guard, s0)      // false
SortedSequence.guardOf(Str.guard, s1)      // true

Since

4.0.0

Type parameters

Name Description
A the expected sequence elements type

Parameters

Name Type Description
g Guardable<A> the elements guard
x unknown the value to check

Returns

x is T<A>

Defined in

src/SortedSequence.ts:127

guardOf<A>(g, x): x is T<A>

Checks if the parameter x is a SortedSequence.T<A> using a GuardableModule<A> functor.

Example

import { SortedSequence, Num, Str } from 'tiinvo'

const s0 = SortedSequence.make(Num, 1, 2)
const s1 = SortedSequence.make(Str, 'hello', 'world')

SortedSequence.guardOf(Str, s0)      // false
SortedSequence.guardOf(Str, s1)      // true

Since

4.0.0

Type parameters

Name Description
A the expected sequence elements type

Parameters

Name Type Description
g GuardableModule<A> the elements guard module
x unknown the value to check

Returns

x is T<A>

Defined in

src/SortedSequence.ts:152

guardOf<A>(g): (x: unknown) => x is T<A>

Returns a guard which checks if the parameter x is a SortedSequence.T<A>

Example

import { SortedSequence, Num, Str } from 'tiinvo'

const s0 = SortedSequence.make(Num, 1, 2)
const s1 = SortedSequence.make(Str, 'hello', 'world')
const isStrSortedList = SortedSequence.guardOf(Str.guard);

isStrSortedList(s0)      // false
isStrSortedList(s1)      // true

Since

4.0.0

Type parameters

Name Description
A the expected sequence elements type

Parameters

Name Type Description
g Guardable<A> the elements guard

Returns

fn

the guard which takes an argument y and returns

▸ (x): x is T<A>

Parameters
Name Type
x unknown
Returns

x is T<A>

Defined in

src/SortedSequence.ts:177

guardOf<A>(g): (x: unknown) => x is T<A>

Returns a guard which checks if the parameter x is a SortedSequence.T<A>

Example

import { SortedSequence, Num, Str } from 'tiinvo'

const s0 = SortedSequence.make(Num, 1, 2)
const s1 = SortedSequence.make(Str, 'hello', 'world')
const isStrSortedList = SortedSequence.guardOf(Str);

isStrSortedList(s0)      // false
isStrSortedList(s1)      // true

Since

4.0.0

Type parameters

Name Description
A the expected sequence elements type

Parameters

Name Type Description
g GuardableModule<A> the elements guard

Returns

fn

the guard which takes an argument y and returns

▸ (x): x is T<A>

Parameters
Name Type
x unknown
Returns

x is T<A>

Defined in

src/SortedSequence.ts:202

Comparables

cmp

cmp<A>(a, b): ComparableResult

Compares two SortedSequence.T<A>.

Example

import { SortedSequence, Num } from 'tiinvo'

const s0 = SortedSequence.make<number>(Num, 0, 1, 2)
const s1 = SortedSequence.make<number>(Num, 0, 1, 2)
const s2 = SortedSequence.make<number>(Num, 0, 1, 2, 3)

SortedSequence.cmp(s0, s1)      // 0
SortedSequence.cmp(s0)(s1)      // 0

SortedSequence.cmp(s0, s2)      // -1
SortedSequence.cmp(s0)(s2)      // -1

SortedSequence.cmp(s2, s0)      // 1
SortedSequence.cmp(s2)(s0)      // 1

Since

4.0.0

Type parameters

Name Type Description
A extends Iterable<any, A> & { [indexer]: () => Readonly<Record<number, any>> ; [iterator]: () => Iterator<any, any, undefined> } & { [sortsymbol]: Comparable<any> } SortedSequence element’s type

Parameters

Name Type Description
a A the first sequence
b A the last sequence

Returns

ComparableResult

Defined in

src/SortedSequence.ts:249

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

Returns a unary function which compares two SortedSequence.T<A>.

Example

import { SortedSequence, Num } from 'tiinvo'

const s0 = SortedSequence.make<number>(Num, 0, 1, 2)
const s1 = SortedSequence.make<number>(Num, 0, 1, 2)
const s2 = SortedSequence.make<number>(Num, 0, 1, 2, 3)
const s3 = SortedSequence.make<number>(Num, 0, 1)

const cmp0 = SortedSequence.cmp(s0);

cmp0(s1)                         // 0
cmp0(s2)                         // 1
cmp0(s3)                         // -1

Since

4.0.0

Type parameters

Name Type Description
A extends Iterable<any, A> & { [indexer]: () => Readonly<Record<number, any>> ; [iterator]: () => Iterator<any, any, undefined> } & { [sortsymbol]: Comparable<any> } SortedSequence.T type

Parameters

Name Type Description
a A the first sequence

Returns

Unary<A, ComparableResult>

the unary function which returns

Defined in

src/SortedSequence.ts:279


eq

eq<A>(a, b): boolean

Checks if two sorted lists are equal

Example

import { SortedSequence, Num } from 'tiinvo'

const s0 = SortedSequence.make<number>(Num, 0, 1, 2)
const s1 = SortedSequence.make<number>(Num, 0, 1, 2)
const s2 = SortedSequence.make<number>(Num, 0, 1, 2, 3)

SortedSequence.eq(s0, s1)      // true
SortedSequence.eq(s0)(s1)      // true

SortedSequence.eq(s0, s2)      // false
SortedSequence.eq(s0)(s2)      // false

Since

4.0.0

Type parameters

Name Type Description
A extends Iterable<any, A> & { [indexer]: () => Readonly<Record<number, any>> ; [iterator]: () => Iterator<any, any, undefined> } & { [sortsymbol]: Comparable<any> } SortedSequence.T type

Parameters

Name Type Description
a A the first sequence
b A the second sequence

Returns

boolean

Defined in

src/SortedSequence.ts:317

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

Returns a unary function which checks if two sorted lists are equal

Example

import { SortedSequence, Num } from 'tiinvo'

const s0 = SortedSequence.make<number>(Num, 0, 1, 2)
const s1 = SortedSequence.make<number>(Num, 0, 1, 2)
const s2 = SortedSequence.make<number>(Num, 0, 1, 2, 3)

SortedSequence.eq(s0, s1)      // true
SortedSequence.eq(s0)(s1)      // true

SortedSequence.eq(s0, s2)      // false
SortedSequence.eq(s0)(s2)      // false

Since

4.0.0

Type parameters

Name Type Description
A extends Iterable<any, A> & { [indexer]: () => Readonly<Record<number, any>> ; [iterator]: () => Iterator<any, any, undefined> } & { [sortsymbol]: Comparable<any> } SortedSequence.T type

Parameters

Name Type Description
a A the first sequence

Returns

Unary<A, boolean>

the unary function which returns

Defined in

src/SortedSequence.ts:344

Mappables

map

map<A, B>(a, m): T<B>

Maps a SortedSequence.T<A> to a SortedSequence.t<b> using the functor Functors.Mappable<a, b>.

Example

import { SortedSequence, Num } from 'tiinvo'

const s = SortedSequence.make<number>(Num, 3, 1, 2)
const m = Num.mul(2)

SortedSequence.map(s, m)        // SortedSequence.t(2, 4, 6)
SortedSequence.map(m)(s)        // SortedSequence.t(2, 4, 6)

Since

4.0.0

Type parameters

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

Parameters

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

Returns

T<B>

the mapped SortedSequence.T<B>

Defined in

src/SortedSequence.ts:382

map<A, B>(a): Unary<T<A>, T<B>>

Returns a unary function which maps a SortedSequence.T<A> to a SortedSequence.t<b> using the functor Functors.Mappable<a, b>.

Example

import { SortedSequence, Num } from 'tiinvo'

const m = SortedSequence.map(Num.mul(2))

m(SortedSequence.make<number>(Num, 3, 1, 2))        // SortedSequence.t(2, 4, 6)
m(SortedSequence.make<number>(Num, 9, 4, 8))        // SortedSequence.t(8, 16, 18)

Since

4.0.0

Type parameters

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

Parameters

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

Returns

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

the unary function which maps SortedSequence.T<A> to SortedSequence.T<B>

Defined in

src/SortedSequence.ts:405

Operables

add

add<A, B>(a, b): T<A & B>

Adds an element to the end of the Sequence.t<a> without mutating the original one.

Example

import { SortedSequence, Num } from 'tiinvo'

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

SortedSequence.add(s0, 30)       // SortedSequence(10, 20, 30)
SortedSequence.add(30)(s0)       // SortedSequence(10, 20, 30)

Since

4.0.0

Type parameters

Name Type Description
A extends Iterable<any, A> & { [indexer]: () => Readonly<Record<number, any>> ; [iterator]: () => Iterator<any, any, undefined> } & { [sortsymbol]: Comparable<any> } the SortedSequence type
B B the added value type

Parameters

Name Type Description
a A the SortedSequence
b B the added value

Returns

T<A & B>

the new SortedSequence

Defined in

src/SortedSequence.ts:445

add<A, B>(a): Unary<A, T<A & B>>

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

Example

import { SortedSequence, Num } from 'tiinvo'

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

SortedSequence.add(s0, 30)       // SortedSequence(10, 20, 30)
SortedSequence.add(30)(s0)       // SortedSequence(10, 20, 30)

Since

4.0.0

Type parameters

Name Type Description
A extends Iterable<any, A> & { [indexer]: () => Readonly<Record<number, any>> ; [iterator]: () => Iterator<any, any, undefined> } & { [sortsymbol]: Comparable<any> } the SortedSequence type
B B the added value type

Parameters

Name Type Description
a B the added value type

Returns

Unary<A, T<A & B>>

the unary function

Defined in

src/SortedSequence.ts:467


concat

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

Concatenates two SortedSequence.T<A> and SortedSequence.T<A> and return a new SortedSequence.T<A>.

Example

import { SortedSequence, Num } from 'tiinvo'

const s0 = SortedSequence.make<number>(Num, 10, 20)
const s1 = SortedSequence.make<number>(Num, 30, 40)

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

Since

4.0.0

Type parameters

Name Description
A the SortedSequence type

Parameters

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

Returns

T<A>

the concatenated SortedSequence

Defined in

src/SortedSequence.ts:501

concat<A>(a): <A>(x: T<A>) => T<A>

Returns a unary function which concatenates two SortedSequence.T<A> and SortedSequence.T<A> and return a new SortedSequence.T<A>.

Example

import { SortedSequence, Num } from 'tiinvo'

const s0 = SortedSequence.make<number>(Num, 10, 20)
const s1 = SortedSequence.make<number>(Num, 30, 40)

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

Since

4.0.0

Type parameters

Name Description
A the SortedSequence type

Parameters

Name Type Description
a T<A> the second SortedSequence

Returns

fn

the unary function

▸ <A>(x): T<A>

Type parameters
Name
A
Parameters
Name Type
x T<A>
Returns

T<A>

Defined in

src/SortedSequence.ts:523

Accessors

count

count<A>(a, p): number

Counts the number of elements that satisfy a given predicate

Example

import { SortedSequence, Num } from 'tiinvo'

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

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

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>

Counts the number of elements that satisfy a given predicate

Example

import { SortedSequence, Num } from 'tiinvo'

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

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

Since

4.0.0

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
a Filterable<A> the sequence

Returns

Unary<T<A>, number>

the number of elements which satisfy the predicate p

Defined in

src/Sequence.ts:1105


get

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

Gets an element at a specific index.

Example

import { SortedSequence, Num } from 'tiinvo'

const s = SortedSequence.make(Num, 'hello', 'world')

SortedSequence.get(s, 0)       // 'hello'
SortedSequence.get(s, 9)       // null

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

Gets an element at a specific index.

Example

import { SortedSequence, Num } from 'tiinvo'

const s = SortedSequence.make(Num, 'hello', 'world')

SortedSequence.get(s, 0)       // 'hello'
SortedSequence.get(s, 9)       // null

Since

4.0.0

Type parameters

Name Description
A the Sequence’s element type

Parameters

Name Type Description
a number the sequence

Returns

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

Defined in

src/Sequence.ts:1195


first

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

Gets first element if any

Example

import { SortedSequence, Num } from 'tiinvo'

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

SortedSequence.first(s0)       // 10
SortedSequence.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


last

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

Gets last element if any.

Example

import { SortedSequence, Num } from 'tiinvo'

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

SortedSequence.last(s0)       // 30
SortedSequence.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


values

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

Gets values of a SortedSequence.T<A> as an immutable indexed object.

Example

import { SortedSequence, Str } from 'tiinvo'

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

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

Functions

length

length<A>(t): number

Gets the length of a SortedSequence.T<A>

Example

import { SortedSequence, Num } from 'tiinvo'

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

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

Predicates

empty

empty<A>(t): boolean

Returns true if the sorted list is empty.

Example

import { SortedSequence, Num } from 'tiinvo'

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

SortedSequence.empty(s)                // true
SortedSequence.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 sorted list is populated.

Example

import { SortedSequence, Num } from 'tiinvo'

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

SortedSequence.populated(s)                      // true
SortedSequence.populated(SortedSequence.make(Num))   // 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

Serializables

toArray

toArray<A>(t): A[]

Converts a SortedSequence.T<A> to an array of a[]

Example

import { SortedSequence, Num } from 'tiinvo'

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

SortedSequence.toArray(sl)       // [1, 2, 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

A[]

the output

Defined in

src/Sequence.ts:1430


toJSON

toJSON<a>(t): a[]

Converts a SortedSequence.T<A> to a jsonizable value

Example

import { SortedSequence, Num } from 'tiinvo'

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

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

Since

4.0.0

Type parameters

Name
a

Parameters

Name Type Description
t T<a> the sequence

Returns

a[]

the output

Defined in

src/Sequence.ts:1449


toMap

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

Converts a SortedSequence.T<A> to a set of Set<a>

Example

import { SortedSequence, Num } from 'tiinvo'

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

SortedSequence.toMap(sl)      // Map([0, 1], [1, 2], [2, 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

Map<string, A>

the output

Defined in

src/Sequence.ts:1469


toSet

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

Converts a SortedSequence.T<A> to a set of Set<a>

Example

import { SortedSequence, Num } from 'tiinvo'

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

SortedSequence.toSet(sl)      // Set(1, 2, 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

Set<A>

the output

Defined in

src/Sequence.ts:1490


toString

toString<A>(t): string

Converts a SortedSequence.T<A> to a string

Example

import { SortedSequence, Num } from 'tiinvo'

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

SortedSequence.toString(sl)       // "1,2,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

string

the output

Defined in

src/Sequence.ts:1511