UNPKG

@jsoldi/hkt

Version:

Higher kinded types for typescript and a few utility monads.

33 lines 1.63 kB
import { $, $3, $B, $K, KRoot } from "../core/hkt.js"; import { IFunctor } from "../classes/functor.js"; import { IMonoid } from "../classes/monoid.js"; /** The tuple type, representing a pair of values. */ export interface KTuple1<L> extends KRoot { readonly 0: unknown; readonly body: [L, this[0]]; } /** The higher-kinded tuple type, representing a pair of values. */ export interface KTuple extends KRoot { readonly 0: unknown; readonly body: KTuple1<this[0]>; } /** The tuple interface, providing a set of functions for working with tuple values. */ export interface ITuple<L = any> extends IFunctor<$<KTuple, L>> { /** Creates a tuple module with a fixed left type. */ of<T>(): ITuple<T>; /** Creates a tuple monoid from the given pair of monoids and fixes the left monoid's type argument. */ monoid<G>(l: IMonoid<$<$K, L>>, r: IMonoid<G>): IMonoid<$3<$B, $<KTuple, L>, G>>; /** Swaps the values of a tuple. */ swap<R>(t: [L, R]): [R, L]; /** Returns the left value of a tuple. */ left<R>(t: [L, R]): L; /** Returns the right value of a tuple. */ right<R>(t: [L, R]): R; /** Maps over the left and right values of a tuple. */ bimap<R, S, T>(t: [L, R], f: (a: L) => S, g: (b: R) => T): [S, T]; /** Maps over the left and right values of a tuple. */ bifmap<R, S, T>(f: (a: L) => S, g: (b: R) => T): (t: [L, R]) => [S, T]; } /** The tuple module, providing functions for working with tuple values. The left type is fixed to `any`. To change the left type, call the `of` function. */ export declare const tuple: ITuple<any>; //# sourceMappingURL=tuple.d.ts.map