tiinvo / Exports / SortedSequence
Ƭ 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.
| Name |
|---|
a |
▸ 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
| Name | Description |
|---|---|
A |
element’s type |
| Name | Type | Description |
|---|---|---|
mod |
Comparable<A> |
the Comparable functor |
...args |
A[] |
a list of initial values |
T<A>
the SortedSequence
▸ 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
| Name | Description |
|---|---|
A |
element’s type |
| Name | Type | Description |
|---|---|---|
mod |
ComparableModule<A> |
the Comparable module functor |
...args |
A[] |
a list of initial values |
T<A>
the SortedSequence
▸ 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
| Name | Type | Description |
|---|---|---|
x |
unknown |
the value to guard |
x is T<unknown>
true if x is a SortedSequence.T<unknown>false otherwise▸ 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
| Name | Description |
|---|---|
A |
the expected sequence elements type |
| Name | Type | Description |
|---|---|---|
g |
Guardable<A> |
the elements guard |
x |
unknown |
the value to check |
x is T<A>
true if x is a SortedSequence.T<A>false otherwise▸ 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
| Name | Description |
|---|---|
A |
the expected sequence elements type |
| Name | Type | Description |
|---|---|---|
g |
GuardableModule<A> |
the elements guard module |
x |
unknown |
the value to check |
x is T<A>
true if x is a SortedSequence.T<A>false otherwise▸ 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
| Name | Description |
|---|---|
A |
the expected sequence elements type |
| Name | Type | Description |
|---|---|---|
g |
Guardable<A> |
the elements guard |
fn
the guard which takes an argument y and returns
true if y is a SortedSequence.T<A>false otherwise▸ (x): x is T<A>
| Name | Type |
|---|---|
x |
unknown |
x is T<A>
▸ 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
| Name | Description |
|---|---|
A |
the expected sequence elements type |
| Name | Type | Description |
|---|---|---|
g |
GuardableModule<A> |
the elements guard |
fn
the guard which takes an argument y and returns
true if y is a SortedSequence.T<A>false otherwise▸ (x): x is T<A>
| Name | Type |
|---|---|
x |
unknown |
x is T<A>
▸ 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
| 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 |
| Name | Type | Description |
|---|---|---|
a |
A |
the first sequence |
b |
A |
the last sequence |
a is less than ba equals ba is greater than b▸ 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
| Name | Type | Description |
|---|---|---|
A |
extends Iterable<any, A> & { [indexer]: () => Readonly<Record<number, any>> ; [iterator]: () => Iterator<any, any, undefined> } & { [sortsymbol]: Comparable<any> } |
SortedSequence.T type |
| Name | Type | Description |
|---|---|---|
a |
A |
the first sequence |
the unary function which returns
b is less than ab equals ab is greater than a▸ 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
| Name | Type | Description |
|---|---|---|
A |
extends Iterable<any, A> & { [indexer]: () => Readonly<Record<number, any>> ; [iterator]: () => Iterator<any, any, undefined> } & { [sortsymbol]: Comparable<any> } |
SortedSequence.T type |
| Name | Type | Description |
|---|---|---|
a |
A |
the first sequence |
b |
A |
the second sequence |
boolean
true if b equals afalse otherwise▸ 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
| Name | Type | Description |
|---|---|---|
A |
extends Iterable<any, A> & { [indexer]: () => Readonly<Record<number, any>> ; [iterator]: () => Iterator<any, any, undefined> } & { [sortsymbol]: Comparable<any> } |
SortedSequence.T type |
| Name | Type | Description |
|---|---|---|
a |
A |
the first sequence |
Unary<A, boolean>
the unary function which returns
true if b equals afalse otherwise▸ 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
| Name | Description |
|---|---|
A |
the SortedSequence element’s type |
B |
the mapped SortedSequence element’s type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the SortedSequence |
m |
Mappable<A, B> |
the Mappable functor |
T<B>
the mapped SortedSequence.T<B>
▸ 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
| Name | Description |
|---|---|
A |
the SortedSequence element’s type |
B |
the mapped SortedSequence element’s type |
| Name | Type | Description |
|---|---|---|
a |
Mappable<A, B> |
the SortedSequence |
the unary function which maps SortedSequence.T<A> to SortedSequence.T<B>
▸ 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
| 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 |
| Name | Type | Description |
|---|---|---|
a |
A |
the SortedSequence |
b |
B |
the added value |
T<A & B>
the new SortedSequence
▸ 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
| 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 |
| Name | Type | Description |
|---|---|---|
a |
B |
the added value type |
the unary function
▸ 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
| Name | Description |
|---|---|
A |
the SortedSequence type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the first SortedSequence |
b |
T<A> |
the second SortedSequence |
T<A>
the concatenated SortedSequence
▸ 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
| Name | Description |
|---|---|
A |
the SortedSequence type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the second SortedSequence |
fn
the unary function
▸ <A>(x): T<A>
| Name |
|---|
A |
| Name | Type |
|---|---|
x |
T<A> |
T<A>
▸ 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
| 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>
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
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
Filterable<A> |
the sequence |
the number of elements which satisfy the predicate p
▸ 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
| 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>>
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
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
a |
number |
the sequence |
Result.Ok<A> if i is in boundResult.Err if i is out of bound or negative▸ 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
| 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▸ 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
| 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▸ 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
| 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
▸ 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
| Name |
|---|
A |
| Name | Type |
|---|---|
t |
T<A> |
number
▸ 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
| 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 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
| Name |
|---|
a |
| Name | Type | Description |
|---|---|---|
t |
T<a> |
the sequence |
boolean
▸ 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
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
t |
T<A> |
the sequence |
A[]
the output
▸ 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
| Name |
|---|
a |
| Name | Type | Description |
|---|---|---|
t |
T<a> |
the sequence |
a[]
the output
▸ 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
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
t |
T<A> |
the sequence |
Map<string, A>
the output
▸ 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
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
t |
T<A> |
the sequence |
Set<A>
the output
▸ 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
| Name | Description |
|---|---|
A |
the Sequence’s element type |
| Name | Type | Description |
|---|---|---|
t |
T<A> |
the sequence |
string
the output