Fun
Functional programming for deno and javascript. Monads, semigroups, optics, parsers, state management, yadda yadda yadda.
Install / Use
/learn @baetheus/FunREADME
functional

Functional is a no dependency utility library for TypeScript and JavaScript that includes a full suite of functional programming tools. Recent versions have moved away from the jargon of Category Theory to a more intuitive naming scheme unique to functional. However, for those that do have existing experience with functional programming or category theory, functional includes many algebraic data types (including implementations of algebraic structures for native javascript structures), type classes, TypeScript-based higher kinded type substitutions, data-last utility combinators, and concrete type utilities.
The primary goals of functional are to be:
- Pragmatic: The API surface of functional should favor ease-of-use and consistency over cleverness or purity. This project is ultimately for getting work done, even it if means a data structure or tools is not mathematically sound in all use cases.
- Understandable: The higher kinded type and algebraic structure implementations are meant to be as simple as possible so their logic can be easily audited. We have also chosen descriptive names for TypeClass implementations instead of ones pulled from Category Theory.
- Performant: Once the first two goals are satisfied, the long term changes within functional are likely going to be beneath the API surface and aimed at speeding things up where possible.
Some non-goals of functional are:
- To be an exact port of fp-ts. Many changes have been implemented throughout functional that diverge sharply from fp-ts, this is often on purpose.
Usage
This library is a collection of smaller tools. This means that each one should be imported separately. There is no barrel export, instead one should pull in the modules they need individually. Following is an example importing from jsr using the deno runtime.
import * as A from "jsr:@baetheus/fun/array";
import { pipe } from "jsr:@baetheus/fun/fn";
pipe(
A.range(5), // get 5 numbers 0-4
A.map((n) => n * n), // square them
console.log, // [ 0, 1, 4, 9, 16 ]
);
Documentation
Documentation is generated for each github tagged release. The latest documentation can be found here. Following is a list of the algebraic data types and algebraic structures/type classes that are implemented in fun. Note that some of these types are both data structures and more general algebraic structures.
| Type | Algebraic Data Type | Algebraic Structure | Native | Other Names | | ------------------------------------ | ------------------- | ------------------- | ------ | ------------------------------------- | | Applicable | | ✓ | | Applicative | | Bimappable | | ✓ | | Bifunctor, Covariant Bifunctor | | Combinable | | ✓ | | Semigroup | | Comparable | | ✓ | | Setoid, Eq | | Composable | | ✓ | | Category | | Failable | | ✓ | | Validation | | Filterable | | ✓ | | | | Flatmappable | | ✓ | | Monad | | Foldable | | ✓ | | Reducible | | Initializable | | ✓ | | Monoid | | Mappable | | ✓ | | Functor, Covariant Functor | | Premappable | | ✓ | | Contravariant, Contravariant Functor | | Schemable | | ✓ | | | | Showable | | ✓ | | Show | | Sortable | | ✓ | | Ord | | Traversable | | ✓ | | | | Wrappable | | ✓ | | Pointed | | Newtype | | | | Brand, Branded Type | | AsyncIterable | ✓ | | ✓ | | | Boolean | ✓ | | ✓ | | | Iterable | ✓ | | ✓ | | | Number | ✓ | | ✓ | | | Promise | ✓ | | ✓ | | | ReadonlyArray | ✓ | | ✓ | Array | | ReadonlyMap | ✓ | | ✓ | Map | | ReadonlySet | ✓ | | ✓ | Set | | String | ✓ | | ✓ | | | Async | ✓ | | | Task | | AsyncEither | ✓ | | | TaskEither | | Decoder | ✓ | | | | | Either | ✓ | | | | | Effect | ✓ | | | AsyncStateEither | | Fn | ✓ | | | Reader | | FnEither | ✓ | | | ReaderEither | | Identity | ✓ | | | Trivial | | JsonSchema | ✓ | | | | | Nilable | ✓ | | | | | Optic | ✓ | | | Iso, Lens, Optional, Prism, Traversal | | Option | ✓ | | | Maybe | | Pair | ✓ | | | Separated | | Parser | ✓ | | | Parsec | | Predicate | ✓ | | | | | Refinement | ✓ | | | | | State | ✓ | | | | | StateEither | ✓ | | | | | Stream | ✓ | | | Observable | | Sync | ✓ | | | IO | | SyncEither | ✓ | | | IOEither | | These | ✓ | | | | | Tree | ✓ | | | |
Major Versions
In the fashion of semantic versioning function makes an effort t
