tiinvo
Version:
A library of types and utilities for your TypeScript and JavaScript projects
1,205 lines (1,204 loc) • 31.3 kB
TypeScript
import type * as Fn from './Fn.js';
import type * as Functors from './Functors.js';
import type * as Option from './Option.js';
import type * as Result from './Result.js';
declare const indexer: unique symbol;
/**
* A `Sequence.T<A>` is an immutable and iterable list of elements `a` in a particular order.
*/
export type T<A> = Iterable<A> & {
[indexer](): Readonly<Record<number, A>>;
[Symbol.iterator](): Iterator<A>;
};
/**
* Try to deserialize a `string` to a `Sequence.T<A>`
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's expected element type
* @param x the string
* @returns
* - `Result.Ok<Sequence.T<A>>` if the deserialization is successful
* - `Result.Err` otherwise
* @group Factories
* @since 4.0.0
*/
export declare const fromString: <A = unknown>(x: string) => Result.T<T<A>>;
/**
* Makes a new `Sequence.T<A>` from an array of `A`.
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* Sequence.make([10, 20, 30]) // Sequence.T<number>
* Sequence.make([1, 2], [3, 4]) // Sequence.T<number[]>
* ```
*
* @template A the type
* @param v the array of initial values
* @returns the `Sequence.T<A>`
* @group Factories
* @since 4.0.0
*/
export declare function make<A>(v: A[]): T<A>;
/**
* Makes a new `Sequence.T<A>` from a list of arguments `a`.
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* Sequence.make(10, 20, 30) // Sequence.T<number>
* ```
*
* @template A the type
* @param v the list of initial values
* @returns the `Sequence.T<A>`
* @group Factories
* @since 4.0.0
*/
export declare function make<A>(...v: A[]): T<A>;
/**
* Checks if a value `x` is a `Sequence.T<unknown>`.
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* Sequence.guard(10) // false
* Sequence.guard([10, 20, 30]) // false
* Sequence.guard(Sequence.make()) // true
* ```
*
* @param x the value to guard
* @returns
* - `true` if `x` is `Sequence.T<unknown>`
* - `false` otherwise
* @group Guardables
* @since 4.0.0
*/
export declare const guard: (x: unknown) => x is T<unknown>;
/**
* Checks if the parameter `x` is a `Sequence.T<A>`
*
* @example
*
* ```ts
* 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
* ```
*
* @template a the type
* @param g the guard
* @returns the new guard which returns
* - `true` if `x` is a `Sequence.T<A>`
* - `false` otherwise
* @group Guardables
* @since 4.0.0
*/
export declare const guardOf: <A>(g: Functors.Guardable<A>) => (x: unknown) => x is T<A>;
/**
* Compares two sequences.
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's element type
* @param mod the comparable functor module
* @param a the first sequence
* @param b the last sequence
* @returns the comparison result `Functors.ComparableResult`
* @group Comparables
* @since 4.0.0
*/
export declare function cmp<A>(mod: Functors.ComparableModule<A>, a: T<A>, b: T<A>): Functors.ComparableResult;
/**
* Compares two sequences.
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's element type
* @param mod the comparable functor
* @param a the first sequence
* @param b the last sequence
* @returns the comparison result `Functors.ComparableResult`
* @group Comparables
* @since 4.0.0
*/
export declare function cmp<A>(mod: Functors.Comparable<A>, a: T<A>, b: T<A>): Functors.ComparableResult;
/**
* Returns a unary function which compares two Sequence
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's element type
* @param mod the comparable functor module
* @param a the first sequence
* @returns the unary function
* @group Comparables
* @since 4.0.0
*/
export declare function cmp<A>(mod: Functors.ComparableModule<A>, a: T<A>): Fn.Unary<T<A>, Functors.ComparableResult>;
/**
* Returns a unary function which compares two Sequence
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's element type
* @param mod the comparable functor
* @param a the first sequence
* @returns the unary function
* @group Comparables
* @since 4.0.0
*/
export declare function cmp<A>(mod: Functors.Comparable<A>, a: T<A>): Fn.Unary<T<A>, Functors.ComparableResult>;
/**
* Returns a binary function which compares two Sequence
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's element type
* @param mod the comparable functor module
* @returns the binary function
* @group Comparables
* @since 4.0.0
*/
export declare function cmp<A>(mod: Functors.ComparableModule<A>): Fn.Binary<T<A>, T<A>, Functors.ComparableResult>;
/**
* Returns a binary function which compares two Sequence
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's element type
* @param mod the comparable functor
* @returns the binary function
* @group Comparables
* @since 4.0.0
*/
export declare function cmp<A>(mod: Functors.Comparable<A>): Fn.Binary<T<A>, T<A>, Functors.ComparableResult>;
/**
* Checks if two sequences are equal
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's element type
* @param mod the equatable module functor
* @param a the first Sequence
* @param b the last Sequence
* @returns
* - `true` if `a` and `b` are equal
* - `false` otherwise
* @group Comparables
* @since 4.0.0
*/
export declare function eq<A>(mod: Functors.EquatableModule<A>, a: T<A>, b: T<A>): boolean;
/**
* Checks if two sequences are equal
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's element type
* @param mod the equatable functor
* @param a the first Sequence
* @param b the last Sequence
* @returns
* - `true` if `a` and `b` are equal
* - `false` otherwise
* @group Comparables
* @since 4.0.0
*/
export declare function eq<A>(mod: Functors.Equatable<A>, a: T<A>, b: T<A>): boolean;
/**
* Returns a unary function which checks if two sequences are equal
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's element type
* @param mod the equatable module functor
* @param a the first Sequence
* @returns the unary function which checks and returns
* - `true` if `a` and `b` are equal
* - `false` otherwise
* @group Comparables
* @since 4.0.0
*/
export declare function eq<A>(mod: Functors.EquatableModule<A>, a: T<A>): Fn.Unary<T<A>, boolean>;
/**
* Returns a unary function which checks if two sequences are equal
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's element type
* @param mod the equatable functor
* @param a the first Sequence
* @returns the unary function which checks and returns
* - `true` if `a` and `b` are equal
* - `false` otherwise
* @group Comparables
* @since 4.0.0
*/
export declare function eq<A>(mod: Functors.Equatable<A>, a: T<A>): Fn.Unary<T<A>, boolean>;
/**
* Returns a binary function which checks if two sequences are equal
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's element type
* @param mod the equatable module functor
* @returns the binary function which checks and returns
* - `true` if `a` and `b` are equal
* - `false` otherwise
* @group Comparables
* @since 4.0.0
*/
export declare function eq<A>(mod: Functors.EquatableModule<A>): Fn.Binary<T<A>, T<A>, boolean>;
/**
* Returns a binary function which checks if two sequences are equal
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's element type
* @param mod the equatable functor
* @returns the binary function which checks and returns
* - `true` if `a` and `b` are equal
* - `false` otherwise
* @group Comparables
* @since 4.0.0
*/
export declare function eq<A>(mod: Functors.Equatable<A>): Fn.Binary<T<A>, T<A>, boolean>;
/**
* Maps a `Sequence.T<A>` to a `Sequence.T<B>` using the functor `Functors.Mappable<a, b>`.
*
* @example
*
* ```ts
* import { Sequence, Num } from 'tiinvo'
*
* const s = Sequence.make(1, 2, 3)
*
* Sequence.map(s, Num.mul(2)) // Sequence.t(2, 4, 6)
* ```
*
* @template A the sequence's element type
* @template B the mapped sequence's element type
* @param a the sequence
* @param m the mappable functor
* @returns the mapped sequence
* @group Mappables
* @since 4.0.0
*/
export declare function map<A, B>(a: T<A>, m: Functors.Mappable<A, B>): 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
*
* ```ts
* import { Sequence, Num } from 'tiinvo'
*
* const s = Sequence.make(1, 2, 3)
*
* Sequence.map(Num.mul(2))(s) // Sequence.t(2, 4, 6)
* ```
*
* @template A the sequence's element type
* @template B the mapped sequence's element type
* @param a the sequence
* @returns the unary function which maps Sequence.T<A> to `Sequence.T<B>`
* @group Mappables
* @since 4.0.0
*/
export declare function map<A, B>(a: Functors.Mappable<A, B>): Fn.Unary<T<A>, T<B>>;
/**
* Reduces all elements `a` to `b` of a `Sequence.T<A>`
*
* @example
*
* ```ts
* import { Sequence, Num } from 'tiinvo'
*
* const s = Sequence.make(10, 20, 30)
*
* Sequence.reduce(s, Num.add, 0) // 60
* ```
*
* @template A the sequence's element type
* @template B the reduced value type
* @param a the sequence
* @param mod the reducer functor
* @param s the starting reduced value
* @returns the reduced value
* @group Mappables
* @since 4.0.0
*/
export declare function reduce<A, B>(a: T<A>, mod: Functors.Reduceable<A, B>, s: B): B;
/**
* Returns a unary function which reduces all elements `a` to `b` of a `Sequence.T<A>`
*
* @example
*
* ```ts
* import { Sequence, Num } from 'tiinvo'
*
* const s = Sequence.make(10, 20, 30)
*
* Sequence.reduce<number, number>(Num.add, 0)(s) // 60
* ```
*
* @template A the sequence's element type
* @template B the reduced value type
* @param a the reducer
* @param mod the starting reduced value
* @returns the unary function. This function takes a `Sequence.T<A>` and reduces it to `B`
* @group Mappables
* @since 4.0.0
*/
export declare function reduce<A, B>(a: Functors.Reduceable<A, B>, mod: B): Fn.Unary<T<A>, B>;
/**
* Filters a `Sequence.T<A>` with a specified `Filterable<a>`
*
* @example
*
* ```ts
* import { Sequence, Num } from 'tiinvo'
*
* const s = Sequence.make(10, 20, 30, 40)
*
* Sequence.filter(s, Num.gt(20)) // Sequence.make(30, 40)
* ```
*
* @template A the Sequence's element type
* @param a the sequence
* @param f the filterable functor
* @returns the filtered sequence
* @group Filterables
* @since 4.0.0
*/
export declare function filter<A>(a: T<A>, f: Functors.Filterable<A>): T<A>;
/**
* Returns a unary function which filters a `Sequence.T<A>` with a specified `Filterable<a>`
*
* @example
*
* ```ts
* import { Sequence, Num } from 'tiinvo'
*
* const s = Sequence.make(10, 20, 30, 40)
*
* Sequence.filter(Num.gt(20))(s) // Sequence.make(30, 40)
* ```
*
* @template A the Sequence's element type
* @param a the filterable functor
* @returns the unary function which takes a sequence and filters it with `a`
* @group Filterables
* @since 4.0.0
*/
export declare function filter<A>(a: Functors.Filterable<A>): Fn.Unary<T<A>, T<A>>;
/**
* Filters and reduce a `Sequence.T<A>` to `B`
*
* **Important** The filter is applied before the reduce.
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the sequence's element type
* @template B the reduced value type
* @param a the sequence
* @param mod the filter and reduce module functor
* @returns the reduced value
* @group Filterables
* @group Mappables
* @since 4.0.0
*/
export declare function filterReduce<A, B>(a: T<A>, mod: Functors.FilterReduceableModule<A, B>): B;
/**
* Returns a unary function which filters and reduce a `Sequence.T<A>` to `B`
*
* **Important** The filter is applied before the reduce.
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the sequence's element type
* @template B the reduced value type
* @param a the filter and reduce module functor
* @returns the unary function which takes a sequence the filters and reduce it to `B`
* @group Filterables
* @group Mappables
* @since 4.0.0
*/
export declare function filterReduce<A, B>(a: Functors.FilterReduceableModule<A, B>): Fn.Unary<T<A>, 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
*
* ```ts
* 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"]
* ```
*
* @template A the sequence's element type
* @template B the mapped sequence's element type
* @param a the sequence
* @param f the filterable and mappable functor
* @returns the filtered and mapped sequence
* @group Filterables
* @group Mappables
* @since 4.0.0
*/
export declare function filterMap<A, B>(a: T<A>, f: Functors.FilterMappableModule<A, B>): 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
*
* ```ts
* 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"]
* ```
*
* @template A the sequence's element type
* @template B the mapped sequence's element type
* @param a the filterable and mappable functor
* @returns the unary function which filters and maps the input sequence `T<A>` to `T<B>`
* @group Filterables
* @group Mappables
* @since 4.0.0
*/
export declare function filterMap<A, B>(a: Functors.FilterMappableModule<A, B>): Fn.Unary<T<A>, T<B>>;
/**
* Adds an element to the end of the `Sequence.T<A>` without mutating the original one.
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* const s0 = Sequence.make(10, 20)
*
* Sequence.append(s0, 30) // Sequence(10, 20, 30)
* ```
*
* @template A the Sequence's element type
* @param a the sequence
* @param b the element to append
* @returns the new sequence
* @group Operators
* @since 4.0.0
*/
export declare function append<A>(a: T<A>, b: A): T<A>;
/**
* Returns a unary function which adds an element to the end of the `Sequence.T<A>`
* without mutating it.
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* const s0 = Sequence.make(10, 20)
*
* Sequence.append(30)(s0) // Sequence(10, 20, 30)
* ```
*
* @template A the Sequence's element type
* @param a the element to append
* @returns the unary function which appends `a` to an existing sequence
* @group Operators
* @since 4.0.0
*/
export declare function append<A>(a: A): Fn.Unary<T<A>, T<A>>;
/**
* Concatenates two `Sequence.T<A>` and `Sequence.T<B>` and return a new `Sequence.T<A & B>`.
*
* @example
*
* ```ts
* 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)
* ```
*
* @template A the first Sequence's element type
* @template B the second Sequence's element type
* @param a the first sequence
* @param b the second sequence
* @returns the concatated sequence
* @group Operators
* @since 4.0.0
*/
export declare function concat<A, B>(a: T<A>, b: 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
*
* ```ts
* 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)
* ```
*
* @template A the first Sequence's element type
* @template B the second Sequence's element type
* @param a the first sequence
* @returns the unary function which concatenates `b` to `a`
* @group Operators
* @since 4.0.0
*/
export declare function concat<A, B>(a: T<A>): Fn.Unary<T<B>, T<A & B>>;
/**
* Adds an element to the start of the `Sequence.T<A>` without mutating the original one.
*
* @example
*
* ```ts
* 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)
* ```
*
* @template A the Sequence's element type
* @param a the sequence
* @param b the element to prepend
* @returns the new sequence with `b` prepended to `a`
* @group Operators
* @since 4.0.0
*/
export declare function prepend<A>(a: T<A>, b: 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
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* const s0 = Sequence.make(10, 20)
*
* Sequence.prepend(30)(s0) // Sequence(30, 10, 20)
* ```
*
* @template A the Sequence's element type
* @param a the element to prepend
* @returns the unary function which prepends `a` to `b`
* @group Operators
* @since 4.0.0
*/
export declare function prepend<A>(a: A): Fn.Unary<T<A>, T<A>>;
/**
* Counts the number of elements that satisfy a given predicate
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's element type
* @param a the sequence
* @param p the Filterable functor
* @returns the number of elements which satisfy the predicate `p`
* @group Accessors
* @since 4.0.0
*/
export declare function count<A>(a: T<A>, p: Functors.Filterable<A>): number;
/**
* Returns a unary function which counts the number of elements that
* satisfy a given predicate
*
* @example
*
* ```ts
* 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
* ```
*
* @template A the Sequence's element type
* @param a the Filterable functor
* @returns the unary function which counts how many elements in `b` satisfy the predicate `p`
* @group Accessors
* @since 4.0.0
*/
export declare function count<A>(a: Functors.Filterable<A>): Fn.Unary<T<A>, number>;
/**
* Gets a `Sequence.T<A>`'s first element.
*
* Returns `Option.None` if none is found.
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* const s0 = Sequence.make(10, 20, 30)
* const s1 = Sequence.make()
*
* Sequence.first(s0) // 10
* Sequence.first(s1) // null
* ```
*
* @template A the Sequence's element type
* @param t the sequence
* @returns the first element of the sequence:
* - `Option.Some<A>` if the sequence has at least one element
* - `Option.None` otherwise
* @group Accessors
* @since 4.0.0
*/
export declare const first: <A>(t: T<A>) => Option.T<A>;
/**
* Gets an element at a specific index.
*
* @example
*
* ```ts
* 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`);
* ```
*
* @template A the Sequence's element type
* @param a the sequence
* @param i the index of the element
* @returns
* - `Result.Ok<A>` if `i` is in bound
* - `Result.Err` if `i` is out of bound or negative
* @group Accessors
* @since 4.0.0
*/
export declare function get<A>(a: T<A>, i: number): Result.T<A>;
/**
* Returns a unary function which gets an element at a specific index.
*
* @example
*
* ```ts
* 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`);
* ```
*
* @template A the Sequence's element type
* @param a the index of the element
* @returns the unary function which accepts a `Sequence.T<A>` and returns
* - `Result.Ok<A>` if `i` is in bound
* - `Result.Err` if `i` is out of bound or negative
* @group Accessors
* @since 4.0.0
*/
export declare function get<A>(a: number): Fn.Unary<T<A>, Result.T<A>>;
/**
* Gets a `Sequence.T<A>`'s last element if any.
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* const s0 = Sequence.make(10, 20, 30)
* const s1 = Sequence.make()
*
* Sequence.last(s0) // 30
* Sequence.last(s1) // null
* ```
*
* @template A the Sequence's element type
* @param t the sequence
* @returns
* - `Option.Some<A>` if the sequence is not empty
* - `Option.None` otherwise
* @group Accessors
* @since 4.0.0
*/
export declare const last: <A>(t: T<A>) => Option.T<A>;
/**
* Gets the length of a `Sequence.T<A>`
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* const s = Sequence.make(1, 2, 3)
*
* Sequence.length(s) // 3
* ```
*
* @template A the Sequence's element type
* @param t the sequence
* @returns the Sequence's length
* @group Accessors
* @since 4.0.0
*/
export declare const length: <A>(t: T<A>) => number;
/**
* Gets values of a `Sequence.T<A>` as an immutable indexed object.
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* const s = Sequence.make('hello', 'world')
*
* Sequence.values(s) // { 0: 'hello', 1: 'world' }
* ```
*
* @template A the Sequence's element type
* @param t the sequence
* @returns the sequence values as an immutable dictionary
* @group Accessors
* @since 4.0.0
*/
export declare const values: <A>(t: T<A>) => Record<number, A>;
/**
* Returns `true` if the sequence is empty.
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* const s = Sequence.make()
* const s1 = Sequence.make(10)
*
* Sequence.empty(s) // true
* Sequence.empty(s1) // false
* ```
*
* @template A the Sequence's element type
* @param t the sequence
* @returns
* - 'true' if the sequence is empty
* - 'false' otherwise
* @group Predicates
* @since 4.0.0
*/
export declare const empty: <A>(t: T<A>) => boolean;
/**
* Returns `true` if the sequence is populated.
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* const s = Sequence.make(10, 20, 30)
*
* Sequence.populated(s) // true
* Sequence.populated(Sequence.make()) // false
* ```
*
* @template A the Sequence's element type
* @param t the sequence
* @returns
* - 'true' if the sequence is populated
* - 'false' otherwise
* @group Predicates
* @since 4.0.0
*/
export declare const populated: <a>(t: T<a>) => boolean;
/**
* Sorts and returns a new `Sequence.T<A>` values with a `Comparable<a>` or `ComparableModule<a>` functor.
*
* @example
*
* ```ts
* 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)
* ```
*
* @template A the Sequence's element type
* @param a the sequence
* @param mod the Comparable functor or the Comparable module functor
* @returns the sorted sequence
* @group Sortables
* @since 4.0.0
*/
export declare function sort<A>(a: T<A>, mod: Functors.Comparable<A> | Functors.ComparableModule<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
*
* ```ts
* 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)
* ```
*
* @template A the Sequence's element type
* @param a the Comparable functor or the Comparable module functor
* @returns the unary function which sorts the passed sequence
* @group Sortables
* @since 4.0.0
*/
export declare function sort<A>(a: Functors.Comparable<A> | Functors.ComparableModule<A>): Fn.Unary<T<A>, T<A>>;
/**
* Converts a `Sequence.T<A>` to an array `a[]`
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* const s = Sequence.make(10, 20, 30)
*
* Sequence.toArray(s) // [10, 20, 30]
* ```
*
* @template A the Sequence's element type
* @param t the sequence
* @returns the array
* @group Serializables
* @since 4.0.0
*/
export declare const toArray: <A>(t: T<A>) => A[];
/**
* Serializes a `Sequence.T<A>` to json
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* Sequence.toJSON(Sequence.make(1, 2)) // { 0: 1, 1: 2 }
* ```
*
* @template A the Sequence's element type
* @param t the sequence
* @returns the JSONised value
* @group Serializables
* @since 4.0.0
*/
export declare const toJSON: <a>(t: T<a>) => a[];
/**
* Serializes a `Sequence.T<A>` to a `Map<number, a>`
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* Sequence.toMap(Sequence.make(1, 2)) // Map([0, 1], [1, 2])
* ```
*
* @template A the Sequence's element type
* @param t the sequence
* @returns the Map
* @group Serializables
* @since 4.0.0
* @since 4.0.0
*/
export declare const toMap: <A>(t: T<A>) => Map<string, A>;
/**
* Converts a `Sequence.T<A>` to a Set `Set<a>`
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* const s = Sequence.make(10, 20, 30)
*
* Sequence.toSet(s) // Set(10, 20, 30)
* ```
*
* @template A the Sequence's element type
* @param t the sequence
* @returns the Set
* @group Serializables
* @since 4.0.0
*/
export declare const toSet: <A>(t: T<A>) => Set<A>;
/**
* Stringifies a `Sequence.T<A>`
*
* @example
*
* ```ts
* import { Sequence } from 'tiinvo'
*
* const s = Sequence.make(10, 20, 30)
*
* Sequence.toString(s) // '10,20,30'
* ```
*
* @template A the Sequence's element type
* @param t the sequence
* @returns the string
* @group Serializables
* @since 4.0.0
*/
export declare const toString: <A>(t: T<A>) => string;
export {};