hkt-toolbelt
Advanced tools
Comparing version 0.1.0 to 0.2.0
# Changelog | ||
## 1.0.0 | ||
## 0.2.0 | ||
- First release | ||
- Added HKT-level composability check for `Kind.Compose`. | ||
## 0.1.0 | ||
- First experimental release | ||
- Introduced `Boolean`, `Cast`, `Conditional`, `Function`, `Kind`, `List`, `String`, and `Test` core components. |
{ | ||
"name": "hkt-toolbelt", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A collection of useful HKT utilities and building blocks", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.ts", |
@@ -43,4 +43,7 @@ # hkt-toolbelt | ||
- [Function](#function) | ||
- [Function.Constant\<A>](#functionconstanta) | ||
- [Function.Identity](#functionidentity) | ||
- [Kind Types](#kind-types) | ||
- [Kind\<F>](#kindf) | ||
- [Kind.Composable\<FX>](#kindcomposablefx) | ||
- [Kind.Compose\<FX>](#kindcomposefx) | ||
@@ -106,2 +109,10 @@ - [Kind.\_](#kind_) | ||
### Function.Constant\<A> | ||
The `Constant` type takes in a type and returns a function that takes in any type and returns the original type. | ||
### Function.Identity | ||
The `Identity` type takes in a type and returns the same type, on the higher-kinded-type level. | ||
## Kind Types | ||
@@ -115,2 +126,6 @@ | ||
### Kind.Composable\<FX> | ||
The `Composable` type checks whether a tuple of kinds are composable. A tuple of kinds is composable if the output of kind N is a subtype of the input of kind N-1. | ||
### Kind.Compose\<FX> | ||
@@ -120,2 +135,4 @@ | ||
`Compose` checks that the tuple of kinds is composable, and returns a higher-kinded-type function that takes in a type and returns the result of the composition. | ||
### Kind.\_ | ||
@@ -122,0 +139,0 @@ |
@@ -18,9 +18,27 @@ import $, { Cast, Function, List } from "hkt-toolbelt"; | ||
export type _$composable< | ||
F extends Kind, | ||
G extends Kind | ||
> = Kind.Output<G> extends Kind.Input<F> ? true : false; | ||
type _$composablePair<F extends [Kind, Kind]> = Kind.Output< | ||
F[1] | ||
> extends Kind.Input<F[0]> | ||
? true | ||
: false; | ||
export abstract class Compose<FX extends Kind[]> extends Kind { | ||
abstract class ComposablePair extends Kind { | ||
abstract f: ( | ||
x: Cast<this[Kind._], [Kind, Kind]> | ||
) => _$composablePair<typeof x>; | ||
} | ||
export type _$composable<FX extends Kind[]> = List._$every< | ||
Kind.ComposablePair, | ||
List._$pair<FX> | ||
>; | ||
export abstract class Composable extends Kind { | ||
abstract f: (x: Cast<this[Kind._], Kind[]>) => _$composable<typeof x>; | ||
} | ||
export abstract class Compose< | ||
FX extends _$composable<FX> extends true ? Kind[] : never | ||
> extends Kind { | ||
abstract f: ( | ||
x: Cast<this[Kind._], FX extends [] ? unknown : Input<List._$last<FX>>> | ||
@@ -27,0 +45,0 @@ ) => _$compose<FX, typeof x>; |
35350
464
187