tiinvo / Exports / TypedSequence
Ƭ T<A>: T<A> & { [guardsymbol]: Guardable<A> }
The typed version of a Sequence.t<A>.
| Name |
|---|
A |
▸ 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
| Name |
|---|
A |
| Name | Type |
|---|---|
g |
Guardable<A> |
...values |
A[] |
T<A>
▸ 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
| Name |
|---|
A |
| Name | Type |
|---|---|
g |
GuardableModule<A> |
...values |
A[] |
T<A>
▸ 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
| Name |
|---|
A |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the TypedSequence |
b |
A |
the value to append |
T<A>
▸ 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
| Name |
|---|
A |
| Name | Type | Description |
|---|---|---|
a |
A |
the value to append |
the unary function
▸ 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
| Name | Type | Description |
|---|---|---|
a |
extends Iterable<any, a> & { [indexer]: () => Readonly<Record<number, any>> ; [iterator]: () => Iterator<any, any, undefined> } & { [guardsymbol]: Guardable<any> } |
the first TypedSequence |
| Name | Type | Description |
|---|---|---|
a |
a |
the last TypedSequence |
b |
a |
- |
a
the concatenated TypedSequence
▸ 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
| Name | Type | Description |
|---|---|---|
a |
extends Iterable<any, a> & { [indexer]: () => Readonly<Record<number, any>> ; [iterator]: () => Iterator<any, any, undefined> } & { [guardsymbol]: Guardable<any> } |
the first TypedSequence |
| Name | Type | Description |
|---|---|---|
a |
a |
the last TypedSequence |
Unary<a, a>
the concatenated TypedSequence
▸ 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
| Name |
|---|
A |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the TypedSequence |
b |
A |
the value to prepend |
T<A>
the new TypedSequence
▸ 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
| Name |
|---|
A |
| Name | Type | Description |
|---|---|---|
a |
A |
the value |
the unary function
▸ 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
| Name |
|---|
A |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the sequence |
p |
Filterable<A> |
- |
number
the counted elements
▸ 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
| Name |
|---|
A |
| Name | Type | Description |
|---|---|---|
a |
Filterable<A> |
the sequence |
the counted elements
▸ 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
| Name |
|---|
A |
| Name | Type |
|---|---|
a |
T<A> |
i |
number |
T<A>
▸ 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
| Name |
|---|
A |
| Name | Type |
|---|---|
a |
number |
▸ 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
| Name |
|---|
A |
| Name | Type |
|---|---|
t |
T<A> |
T<A>
▸ 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
| Name |
|---|
A |
| Name | Type |
|---|---|
t |
T<A> |
number
▸ 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
| Name |
|---|
A |
| Name | Type |
|---|---|
t |
T<A> |
Record<number, A>
▸ 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
| Name |
|---|
A |
| Name | Type |
|---|---|
t |
T<A> |
boolean
▸ 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
| Name |
|---|
a |
| Name | Type |
|---|---|
t |
T<a> |
boolean
▸ 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
| Name | Type | Description |
|---|---|---|
x |
unknown |
the guarded value |
x is T<unknown>
▸ 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
| Name | Description |
|---|---|
A |
the sequence type |
| Name | Type | Description |
|---|---|---|
a |
T<A> |
the sequence |
mod |
Comparable<A> | ComparableModule<A> |
the Comparable used to sort the sequence |
T<A>
the sorted sequence
▸ 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
| Name | Description |
|---|---|
A |
the sequence type |
| Name | Type | Description |
|---|---|---|
a |
Comparable<A> | ComparableModule<A> |
the sequence |
the sorting unary function
▸ 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
| Name | Description |
|---|---|
A |
the sequence’s element type |
| 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 |
the comparison result
▸ 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
| Name | Description |
|---|---|
A |
the sequence’s element type |
| Name | Type | Description |
|---|---|---|
cmp |
Comparable<A> | ComparableModule<A> |
the Comparable<A> or ComparableModule<A> functor |
a |
T<A> |
the first sequence |
Unary<T<A>, ComparableResult>
the comparer function
▸ 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
| Name | Description |
|---|---|
A |
the sequence’s element type |
| Name | Type | Description |
|---|---|---|
cmp |
Comparable<A> | ComparableModule<A> |
the Comparable<A> or ComparableModule<A> functor |
Binary<T<A>, T<A>, ComparableResult>
the comparer function
▸ 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
| Name | Description |
|---|---|
A |
the sequence’s element type |
| 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 |
boolean
true if the sequences are equal, false otherwise
▸ 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
| Name | Description |
|---|---|
A |
the sequence’s element type |
| Name | Type | Description |
|---|---|---|
eq |
Equatable<A> | EquatableModule<A> |
the Equatable<A> or EquatableModule<A> functor |
a |
T<A> |
the first sequence |
the comparer function
▸ 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
| Name | Description |
|---|---|
A |
the sequence’s element type |
| Name | Type | Description |
|---|---|---|
eq |
Equatable<A> | EquatableModule<A> |
the Equatable<A> or EquatableModule<A> functor |
the comparer function
▸ 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
| Name |
|---|
A |
| Name | Type |
|---|---|
t |
T<A> |
A[]
the array
▸ 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
| Name |
|---|
a |
| Name | Type |
|---|---|
t |
T<a> |
a[]
the JSON
▸ 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
| Name |
|---|
A |
| Name | Type |
|---|---|
t |
T<A> |
Map<string, A>
the Map
▸ 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
| Name |
|---|
A |
| Name | Type |
|---|---|
t |
T<A> |
Set<A>
the Set
▸ 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
| Name |
|---|
A |
| Name | Type |
|---|---|
t |
T<A> |
string