UNPKG

rivo

Version:

🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.

29 lines (25 loc) • 956 B
import type { List } from "."; import type { Args, GenericFn, GenericResolver } from "../HKT"; import type { Nat } from "../Num"; import type { GTE } from "../Num/GTE"; import type { None, Option, Some } from "../Option"; /** * Get the element at a specific index in a {@link List}. * * Sig: `<T>(i: Nat, xs: List<T>) => Option<T>` */ export type At<I extends Nat, TS extends List> = GTE<I, TS["length"]> extends true ? None : Some<TS[I]>; interface Resolver extends GenericResolver<[Nat, List], Option<unknown>> { on1_: ([i]: Args<this>) => [[List], Option<unknown>]; on_1: ([, xs]: Args<this>) => [[Nat], Option<(typeof xs)[number]>]; on11: ([i, xs]: Args<this>) => [[], Option<(typeof xs)[number]>]; } /** * Get the element at a specific index in a {@link List}. * * Sig: `<T>(i: Nat, xs: List<T>) => Option<T>` */ export default interface AtFn extends GenericFn<Resolver> { def: ([i, xs]: Args<this>) => At<typeof i, typeof xs>; }