0.26.0 • Published 7 months ago

hkt-toolbelt v0.26.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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"]>;  // ["hello", "world"]

type OneTwoThree = $<
  $<List.Filter, $<Conditional.Extends, number>>,
  [1, "foo", 2, 3, "bar"]
>; // [1, 2, 3]

2) $N: Pass Multiple Arguments into an uncurried Function

$N<KIND, [ARG1, ARG2, ...]>

import { $, $N, List, NaturalNumber } from "hkt-toolbelt";

// Example 1: full application (invoked with all three arguments)
type ReduceSum1to5 = $N<List.Reduce, [
  NaturalNumber.Add,  // callback
  0,                  // initial value
  [1, 2, 3, 4, 5]     // target array
]>;  // 15

// Example 2: partial application (invoked with only the first two arguments)
type ReduceSum = $N<List.Reduce, [NaturalNumber.Add, 0]>;
type ReduceSum1to5 = $<ReduceSum, [1, 2, 3, 4, 5]>;  // 15
type ReduceSum1to10 = $<ReduceSum, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]>;  // 55

3) $$: Pipe an Argument through Multiple Functions

$$<[KIND1, KIND2, ...], ARG>

import { $, $$, List, String } from "hkt-toolbelt";

type UnshiftPushJoin = $$<[
    $<List.Unshift, "first">,  // ["first", "second"]
    $<List.Push, "third">,     // ["first", "second", "third"]
    $<String.Join, ", ">,      // "first, second, third"
  ], ["second"]>;
0.25.2

8 months ago

0.25.1

8 months ago

0.25.0

8 months ago

0.26.0

7 months ago

0.24.10

10 months ago

0.24.5

10 months ago

0.24.4

11 months ago

0.24.3

11 months ago

0.24.11

10 months ago

0.24.2

11 months ago

0.24.1

11 months ago

0.24.0

11 months ago

0.24.9

10 months ago

0.24.8

10 months ago

0.24.7

10 months ago

0.24.6

10 months ago

0.23.1

1 year ago

0.23.0

1 year ago

0.22.2

2 years ago

0.22.1

2 years ago

0.22.0

2 years ago

0.22.0-beta.1

2 years ago

0.21.0

2 years ago

0.20.1

2 years ago

0.20.0

2 years ago

0.19.3

2 years ago

0.21.1

2 years ago

0.19.0

3 years ago

0.18.1

3 years ago

0.19.1

3 years ago

0.19.2

3 years ago

0.18.0

3 years ago

0.17.1

3 years ago

0.17.0

3 years ago

0.16.1

3 years ago

0.15.1

3 years ago

0.15.0

3 years ago

0.14.0

3 years ago

0.13.2

3 years ago

0.13.1

3 years ago

0.13.0

3 years ago

0.12.0

3 years ago

0.11.0

3 years ago

0.10.0

3 years ago

0.9.0

3 years ago

0.8.2

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.0

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.4

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago

1.0.0

3 years ago