Rivo
The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.
import type { $, Ask, Flow, List, Num, Ord, Pipe, Show, Sig, Some, Str, Tuple$$Of1 } from "rivo";
type R1 = Pipe<[-1, 0, 1], List.Every<Num.IsPos>>;
type R2 = Pipe<123, Show.Show, Str.ToChars, List.Every<Str.IsDigit>>;
type R3 = $<Str.Length, "foo">;
type IsEveryPositive = List.Every<Num.IsPos>;
type R4 = $<IsEveryPositive, [1, 2, 3]>;
type R5 = $<Str.Concat, "foo", "bar">;
type R6 = $<Str.Append<"bar">, "foo">;
type IsEveryPositiveSig = Sig<IsEveryPositive>;
type R7 = $<Str.Append<"foo">, 123>;
type R8 = $<Str.Append<"foo">, "bar", "baz">;
type Append42 = Str.Append<42>;
type IsNaturalNumberFn = Flow<Show.Show, Str.ToChars, List.Every<Str.IsDigit>>;
type R9 = $<IsNaturalNumberFn, 123>;
type R10 = $<IsNaturalNumberFn, 123.5>;
type F1 = Flow<Show.Show, List.Every<Num.IsPos>>;
type R11 = Pipe<"123", Str.ToChars, List.Map<Num.IsPos>>;
type R12 = Sig<Flow<Ask<number>, Tuple$$Of1>>;
type R13 = Sig<Flow<Ask<string>, Tuple$$Of1>>;
type R14 = $<Ord.Compare, 1, 2>;
type R15 = $<Ord.Compare, Some<42>, Some<43>>;
type R16 = $<Ord.Compare, Some<Some<55>>, Some<Some<55>>>;
Build your own type level functions with ease.
import type { $, Args, Call2, Fn, PartialApply } from "rivo";
import type { Dec } from "rivo/Num/Int/Dec";
interface RepeatStringFn extends Fn<[number, string], string> {
def: ([n, s]: Args<this>) => typeof n extends 0 ? ""
: `${typeof s}${Call2<RepeatStringFn, Dec<typeof n>, typeof s>}`;
}
type R1 = $<RepeatStringFn, 3, "foo">;
type RepeatString<N extends number> = PartialApply<RepeatStringFn, [N]>;
type R2 = $<RepeatString<3>, "foo">;
... and much more! Rivo provides great documentation and examples to get you started, just explore them!
Note: Rivo requires TypeScript 5.0 or above.
Installation
npm install --save-dev rivo
yarn add -D rivo
pnpm add -D rivo
bun install --dev rivo