🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.
npm install rivoThe ultimate library you need for composable type-level programming in TypeScript, powered by HKT.
``typescript
import type { $, Ask, Flow, List, Num, Ord, Pipe, Show, Sig, Some, Str, Tuple$$Of1 } from "rivo";
// Rivo provides out-of-the-box type level functions, following point-free style
type R1 = Pipe<[-1, 0, 1], List.Every
// ^?: false
type R2 = Pipe<123, Show.Show, Str.ToChars, List.Every
// ^?: true
// These functions can be called using $ (Call) or Apply,Pipe
// or if it accepts only one argument (as you can see above)
type R3 = $
// ^?: 3
type IsEveryPositive = List.Every
type R4 = $
// ^?: true
type R5 = $
// ^?: "foobar"
type R6 = $
// ^?: "foobar"
// Use Sig to get the signature of a type level function (for debugging)
type IsEveryPositiveSig = Sig
// Type safety is guaranteed when using $ and Call
type R7 = $
// ~~~
// Type 'number' does not satisfy the constraint 'string'
type R8 = $
// ~~~~~
// Type 'string' does not satisfy the constraint 'never'
type Append42 = Str.Append<42>;
// ~~
// Type 'number' does not satisfy the constraint 'string'
// You can easily combine multiple type level functions into one using Flow
type IsNaturalNumberFn = Flow
type R9 = $
// ^?: true
type R10 = $
// ^?: false
// Type safety is still guaranteed even when using Flow and Pipe
type F1 = Flow
// ~~~~~~~~~~~~~~~~~~~~~
// Type 'string' is not assignable to type 'List
type R11 = Pipe<"123", Str.ToChars, List.Map
// ~~~~~~~~~~~~~~~~~~~
// Type 'string' is not assignable to type 'number'
// Type level functions can be even generic (see GenericFn and GenericResolver for more info)
type R12 = Sig
// ^?: (n: number) => readonly [number]
type R13 = Sig
// ^?: (n: string) => readonly [string] <- Changes based on the input type
// Even type-level type classes! CRAZY! (see inside rivo/typeclass for more info)`
type R14 = $
// ^?: -1
type R15 = $
// ^?: -1
type R16 = $
// ^?: 0
Build your own type level functions with ease.
`typescript
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
: ${typeof s}${Call2;
}
type R1 = $
// ^?: "foofoofoo"
// You can partial apply the function to create a new function
type RepeatString
type R2 = $
// ^?: "foofoofoo"
`
... and much more! Rivo provides great documentation and examples to get you started, just explore them!
Note: Rivo requires TypeScript 5.0 or above.
`bash``
npm install --save-dev rivoOr
yarn add -D rivoOr
pnpm add -D rivoOr
bun install --dev rivo