Functional programming in TypeScript
fp-ts
is a library for typed functional programming in TypeScript.
fp-ts
aims to allow developers to use popular patterns and abstractions that are available in most functional languages. For this, it includes the most popular data types, type classes and abstractions such as Option
, Either
, IO
, Task
, Functor
, Applicative
, Monad
to empower users to write pure FP apps and libraries built atop higher order abstractions.
A distinctive feature of fp-ts
with respect to other functional libraries is its implementation of Higher Kinded Types (TypeScript doesn't support HKT natively).
The idea (faking higher kinded types in TypeScript) is based on Lightweight higher-kinded polymorphism
Inspired by
- Installation and TypeScript compatibility
- Getting started
- Documentation
- Ecosystem
- Type Classes Diagram
- License
To install the stable version:
npm install fp-ts
The stable version is tested against TypeScript 3.3.3, but should run with TypeScript 2.8.0+ too
Note. This library is conceived, tested and is supposed to be consumed by TypeScript with the strict
flag turned on.
Note. If you are running < typescript@3.0.1
you have to polyfill the unknown
type. You can use unknown-ts as a polyfill.
Note. Make sure to always have a single version of fp-ts
installed in your project. Multiple versions are known to cause tsc
to hang during compilation. You can check the versions currently installed using npm ls fp-ts
(make sure there's a single version and all the others are marked as deduped
).
If you are coming from JavaScript:
- read Mostly adequate guide to FP by @DrBoolean
- read this blog series on functional programming in JavaScript by Tom Harding, and then check out the code translated to TypeScript (there's a file for each blog post)
If you are using ramda
If you are coming from TypeScript:
If you are coming from Haskell or Purescript:
- Interoperability with non functional code using fp-ts
- Functional design: combinators
- Functional design: how to make the
time
combinator more general - Functional design: tagless final
Beginner
Advanced
- Free monad and
fp-ts
(code) - MTL-style in
fp-ts
(code) - Type safe finite state machines with
IxIO
(code)
- fp-ts-codegen - TypeScript code generation from a haskell-like syntax for ADT
- io-ts - TypeScript compatible runtime type system for IO validation
- monocle-ts - Functional optics: a (partial) porting of scala monocle to TypeScript
- newtype-ts - Implementation of newtypes in TypeScript
- logging-ts - Composable loggers for TypeScript
- fp-ts-routing - A type-safe bidirectional routing library for TypeScript
- parser-ts - String parser combinators for TypeScript
- remote-data-ts - RemoteData type (check this article)
- retry-ts - Retry combinators for monadic actions that may fail
- fp-ts-local-storage - fp-ts bindings for LocalStorage
- circuit-breaker-monad - Circuit Breaker pattern as a monad
- fp-ts-rxjs - fp-ts bindings for RxJS
- fp-ts-fluture - fp-ts bindings for Fluture
- fp-ts-most - fp-ts bindings for @most/core
(click on the diagram to enlarge)
The MIT License (MIT)