UNPKG

rivo

Version:

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

30 lines (26 loc) • 1.03 kB
import type { List } from "."; import type { Args, Fn } from "../HKT"; import type { AssertStr } from "../helpers"; import type { Show } from "../typeclass/Show"; import type { Show as Show_ } from "../typeclass/Show/Show"; type _Print<S extends Show> = S extends string ? S : Show_<S>; /** * Join a {@link List} of {@link Show}s into a single string. * * Sig: `(sep: Show, xs: List<Show>) => string` */ export type Join<Sep extends Show, TS extends List<Show>> = AssertStr< TS extends readonly [infer Head extends Show] ? _Print<Head> : TS extends readonly [infer Head extends Show, ...infer Tail extends List<Show>] ? // @ts-ignore - Type instantiation is excessively deep and possibly infinite. `${_Print<Head>}${_Print<Sep>}${Join<Sep, Tail>}` : "" >; /** * [Fn] Join a {@link List} of {@link Show}s into a single string. * * Sig: `(sep: Show, xs: List<Show>) => string` */ export interface JoinFn extends Fn<[Show, List<Show>], string> { def: ([sep, xs]: Args<this>) => Join<typeof sep, typeof xs>; }