Functional and composable type utilities
hkt-toolbelt
is a collection of type-level utilities that can be mapped and combined in functional ways using higher-kinded types.
Our composable and compile time-efficient types enable users to write expressive and readable type-level code without getting mired in complexity.
Getting Started
Install
> npm install hkt-toolbelt
> yarn add hkt-toolbelt
Import
import {
$, $$, $N,
Boolean, Conditional, Function,
List, Object, String, Union,
Number, Integer, NaturalNumber,
Kind, Type, Combinator, Parser,
} from "hkt-toolbelt";
Usage
1) $
: Apply a Function to an Argument
$<KIND, ARG>
import { $, List, Conditional } from "hkt-toolbelt";
type HelloWorld = $<$<List.Push, "world">, ["hello"]>;
type OneTwoThree = $<
$<List.Filter, $<Conditional.Extends, number>>,
[1, "foo", 2, 3, "bar"]
>;
2) $N
: Pass Multiple Arguments into an uncurried Function
$N<KIND, [ARG1, ARG2, ...]>
import { $, $N, List, NaturalNumber } from "hkt-toolbelt";
type ReduceSum1to5 = $N<List.Reduce, [
NaturalNumber.Add,
0,
[1, 2, 3, 4, 5]
]>;
type ReduceSum = $N<List.Reduce, [NaturalNumber.Add, 0]>;
type ReduceSum1to5 = $<ReduceSum, [1, 2, 3, 4, 5]>;
type ReduceSum1to10 = $<ReduceSum, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]>;
3) $$
: Pipe an Argument through Multiple Functions
$$<[KIND1, KIND2, ...], ARG>
import { $, $$, List, String } from "hkt-toolbelt";
type UnshiftPushJoin = $$<[
$<List.Unshift, "first">,
$<List.Push, "third">,
$<String.Join, ", ">,
], ["second"]>;