UNPKG

rivo

Version:

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

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