Package Exports
- fp-ts
- fp-ts/lib/Applicative
- fp-ts/lib/Apply
- fp-ts/lib/Array
- fp-ts/lib/Array.js
- fp-ts/lib/Chain
- fp-ts/lib/ChainRec
- fp-ts/lib/Const
- fp-ts/lib/Contravariant
- fp-ts/lib/Either
- fp-ts/lib/Either.js
- fp-ts/lib/EitherT
- fp-ts/lib/Extend
- fp-ts/lib/Field
- fp-ts/lib/Filterable
- fp-ts/lib/Foldable
- fp-ts/lib/Free
- fp-ts/lib/Functor
- fp-ts/lib/IO
- fp-ts/lib/Identity
- fp-ts/lib/Monoid
- fp-ts/lib/NonEmptyArray
- fp-ts/lib/Option
- fp-ts/lib/Option.js
- fp-ts/lib/OptionT
- fp-ts/lib/Ord
- fp-ts/lib/Ordering
- fp-ts/lib/Reader
- fp-ts/lib/ReaderT
- fp-ts/lib/Semigroup
- fp-ts/lib/Setoid
- fp-ts/lib/State
- fp-ts/lib/StateT
- fp-ts/lib/Task
- fp-ts/lib/These
- fp-ts/lib/Traversable
- fp-ts/lib/Tuple
- fp-ts/lib/Validation
- fp-ts/lib/Writer
- fp-ts/lib/function
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fp-ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
A mix of
- fantasy-land
- static-land
- PureScript
- Scala
See the section "Technical overview" below for an explanation of the technique.
Installation
To install the stable version:
npm install --save fp-ts
Documentation
Algebraic types
Array | Option | Either | NEA(*) | Task | Const | Identity | Validation | |
---|---|---|---|---|---|---|---|---|
Setoid | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ |
Semigroup | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
Monoid | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ |
Functor | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Contravariant | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ |
PointedFunctor | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Apply | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Applicative | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Alt | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ |
Plus | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
Alternative | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
Foldable | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ |
Traversable | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ |
Chain | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ |
ChainRec | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
Extract | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ |
Extend | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ |
Comonad | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ |
Bifunctor | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
(*) NonEmptyArray
Monads
- Array
- Either
- Identity
- Option
- Reader
- State
- Task
- Writer
Comonads
- Identity
- Store
- Traced
Monad transformers
- EitherT
- OptionT
- ReaderT
- StateT
Technical overview
Higher kinded types and type classes
Higher kinded types are represented by a unique string literal (called URI
).
There's a central type dictionary where a mapping URI
-> concrete type is stored
// file ./HTK.ts
export interface HKT<A> {}
Instances can be defined (everywhere) using a feature called Module Augmentation so there's no danger of name conflict (the typechecker checks for duplicates).
Here's a mapping between the string literal 'Option'
and the concrete type Option<A>
// file ./Option.ts
declare module './HKT' {
interface HKT<A> {
Option: Option<A>
}
}
export const URI = 'Option'
export type URI = typeof URI
export type Option<A> = None<A> | Some<A>
export class None<A> {
readonly _URI: URI
map<B>(f: (a: A) => B): Option<B> {
return none
}
...
}
export Some<A> {
readonly _URI: URI
// fantasy-land implementation
map<B>(f: (a: A) => B): Option<B> {
return new Some(f(this.value))
}
...
}
// static-land implementation
export function map<A, B>(f: (a: A) => B, fa: Option<A>): Option<B> {
return fa.map(f)
}
Concrete types can be retrieved by their URI
using a feature called Index types.
Type classes are implemented following (when possible) both the static-land spec and the fantasy-land spec.
Here's the definition of the type class Functor
(following the static-land spec)
export interface Functor<F extends HKTS> {
URI: F
map<A, B>(f: (a: A) => B, fa: HKT<A>[F]): HKT<B>[F]
}
License
The MIT License (MIT)