UNPKG

rivo

Version:

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

25 lines (21 loc) • 693 B
import type { List } from "."; import type { Args, GenericFn, GenericResolver } from "../HKT"; import type { None, Option, Some } from "../Option"; /** * Get the first element in a {@link List}. * * Sig: `<T>(xs: List<T>) => Option<T>` */ export type Head<TS extends List> = TS extends readonly [infer Head, ...unknown[]] ? Some<Head> : None; interface Resolver extends GenericResolver<[List], Option<unknown>> { on1: ([xs]: Args<this>) => [[], Option<(typeof xs)[number]>]; } /** * Get the first element in a {@link List}. * * Sig: `<T>(xs: List<T>) => Option<T>` */ export default interface HeadFn extends GenericFn<Resolver> { def: ([xs]: Args<this>) => Head<typeof xs>; }