fp-ts

TypeScript 中的函数式编程。「Functional programming in TypeScript」

Github stars Tracking Chart

Typed 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, which TypeScript doesn't support natively.

Inspired by

Table of contents

Installation

To install the stable version:

npm install fp-ts

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).

Consuming fp-ts

Most examples will use the following import syntax:

import { Option, some, none } from 'fp-ts/lib/Option'

This will give you the widest support across tools, as you will be importing CommonJS modules.

If you use a bundler such as webpack or Rollup that supports tree-shaking, you can take advantage of this by opting to import ECMAScript modules instead:

import { Option, some, none } from 'fp-ts/es6/Option'

Note that there are caveats such as some tools (e.g. Jest) not supporting ES6 module syntax natively yet.

TypeScript compatibility

Strictness – This library is conceived, tested and is supposed to be consumed by TypeScript with the strict flag turned on.

Main metrics

Overview
Name With Ownergcanti/fp-ts
Primary LanguageTypeScript
Program languageTypeScript (Language Count: 2)
PlatformLinux, Mac, Windows
License:MIT License
所有者活动
Created At2017-01-25 17:44:09
Pushed At2025-04-18 09:22:55
Last Commit At2025-04-18 11:22:51
Release Count186
Last Release Name2.16.9 (Posted on )
First Release Name0.0.1 (Posted on )
用户参与
Stargazers Count11.2k
Watchers Count98
Fork Count512
Commits Count2.9k
Has Issues Enabled
Issues Count819
Issue Open Count156
Pull Requests Count867
Pull Requests Open Count34
Pull Requests Close Count121
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private