@jsoldi/hkt
Version:
Higher kinded types for typescript and a few utility monads.
59 lines • 3.35 kB
TypeScript
import { $, $B2, $Q, KRoot } from "../core/hkt.js";
import { IMonad } from "../classes/monad.js";
import { IFold } from "../classes/fold.js";
import { IMonadTrans, ITransformer } from "../classes/transformer.js";
import { IMonadPlus } from "../classes/monadPlus.js";
import { ITraversable } from "../classes/traversable.js";
import { IFoldable } from "../classes/foldable.js";
import { IUnfoldable } from "../classes/unfoldable.js";
/** The array higher-kinded type. */
export interface KArray extends KRoot {
readonly 0: unknown;
readonly body: Array<this[0]>;
}
/** The array transformer higher-kinded type. */
export type KArrayTrans = $<$Q, KArray>;
/** The array interface. */
export interface IArray extends IMonadPlus<KArray>, IFoldable<KArray>, IUnfoldable<KArray>, ITraversable<KArray>, ITransformer<KArrayTrans> {
/** Folds the values of `fa` from right to left using the given function and initial value. */
foldr<A, B>(f: (a: A, b: B) => B): (b: B) => (fa: A[]) => B;
/** Filters the items of an array using a predicate function. */
filter<T, S extends T>(predicate: (item: T) => item is S): (items: T[]) => S[];
/** Filters the items of an array using a predicate function. */
filter<T>(predicate: (item: T) => unknown): (items: T[]) => T[];
/** Splits an array into chunks of the given size. */
chunks(size: number): <A>(fa: A[]) => A[][];
/** Removes duplicate items from an array using a key function. */
distinctBy<A, B>(f: (a: A) => B): (fa: A[]) => A[];
/** Maps an async function over an array, running promises sequentially. */
mapAsync: <A, B>(f: (a: A) => Promise<B>) => (fa: A[]) => Promise<B[]>;
/** Takes the first `n` items of an array. */
take<A>(n: number): (fa: A[]) => A[];
/** Skips the first `n` items of an array. */
skip<A>(n: number): (fa: A[]) => A[];
/** Zips two arrays into an array of pairs. */
zip<A, B>(fa: A[], fb: B[]): [A, B][];
/** Produces a monad transformer having `Array` as the inner monad. */
transform<M>(base: IMonad<M>): IArrayTrans<M>;
/** Lifts the array monoid into a monad. */
liftMonoid<M>(base: IMonad<M>): IArrayTrans<M>;
/** Sequences an array of monads into a monad of an array. */
sequence<M>(m: IMonad<M>): {
(ta: []): $<M, []>;
<A>(ta: [$<M, A>]): $<M, [A]>;
<A, B>(ta: [$<M, A>, $<M, B>]): $<M, [A, B]>;
<A, B, C>(ta: [$<M, A>, $<M, B>, $<M, C>]): $<M, [A, B, C]>;
<A, B, C, D>(ta: [$<M, A>, $<M, B>, $<M, C>, $<M, D>]): $<M, [A, B, C, D]>;
<A, B, C, D, E>(ta: [$<M, A>, $<M, B>, $<M, C>, $<M, D>, $<M, E>]): $<M, [A, B, C, D, E]>;
<A, B, C, D, E, F>(ta: [$<M, A>, $<M, B>, $<M, C>, $<M, D>, $<M, E>, $<M, F>]): $<M, [A, B, C, D, E, F]>;
<A, B, C, D, E, F, G>(ta: [$<M, A>, $<M, B>, $<M, C>, $<M, D>, $<M, E>, $<M, F>, $<M, G>]): $<M, [A, B, C, D, E, F, G]>;
<A, B, C, D, E, F, G, H>(ta: [$<M, A>, $<M, B>, $<M, C>, $<M, D>, $<M, E>, $<M, F>, $<M, G>, $<M, H>]): $<M, [A, B, C, D, E, F, G, H]>;
<A>(ta: $<M, A>[]): $<M, A[]>;
};
}
/** The array transformer interface. */
export interface IArrayTrans<M> extends IMonadTrans<KArrayTrans, M>, IFold<$B2<M, KArray>, M>, IMonadPlus<$B2<M, KArray>> {
}
/** The array module. */
export declare const array: IArray;
//# sourceMappingURL=array.d.ts.map