kung-fu
Functional Standard Library with TypeScript support
Kung-fu aims to provide a collection of immutable datastructures and functional algorithms that can be used to create robust JavaScript and TypeScript programs.
It is written in TypeScript to ensure a type-safe and idiomatic implementation.
Installation
Kung-fu is available on npm:
npm install kung-fu
Features
Option<T>
Option can be used to represent an optional value, without having to resort to null
and undefined
. It can be empty, or contain a value of type T.
zeroAsDefaultOption.some42 // == 42zeroAsDefaultOption.none // == 0
Either<L, R>
Either can be used to represent a result with two different outcomes, e.g. error or success.
doSomethingDangeroustrue // == Either.right('wow, it worked. lucky you!');doSomethingDangeroustrue.flatMapdoSomethingDangerousfalse // == Either.left(new Error('uh oh!'))
Pair<A, B>
Pair can be used to represent a heterogenous tuple of two values.
; twoThings.mapFirststr + '!' // == new Pair('one thing!', 42);
PartialFunction<From, To>
A partial function from From
to To
.
; partial.call42.getOr0;