fp-ts

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

Github星跟踪图

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.

主要指标

概览
名称与所有者gcanti/fp-ts
主编程语言TypeScript
编程语言TypeScript (语言数: 2)
平台Linux, Mac, Windows
许可证MIT License
所有者活动
创建于2017-01-25 17:44:09
推送于2025-04-18 09:22:55
最后一次提交2025-04-18 11:22:51
发布数186
最新版本名称2.16.9 (发布于 )
第一版名称0.0.1 (发布于 )
用户参与
星数11.2k
关注者数98
派生数512
提交数2.9k
已启用问题?
问题数819
打开的问题数156
拉请求数867
打开的拉请求数34
关闭的拉请求数121
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?