neotype_prelude

neotype_prelude

Functional programming essentials for TypeScript

Build and Test NPM Version

Quick links

Features

  • Tools for comparing values: use the contracts provided by the Eq and Ord interfaces to implement equivalence relations and total orders.
  • Tools for combining values: use the contract provided by the Semigroup interface to implement semigroups.
  • Algebraic data types:
    • Model optional values with Maybe.
    • Handle failures with Either.
    • Validate forms and user input with Validation.
    • Get creative with more types like Ior and Pair.
  • Generator comprehensions: chain computations together by writing imperative style code blocks using a coroutine syntax.
  • Async generator comprehensions: work with Promise values inside of generator comprehensions using async/await syntax.

Install

neotype_prelude is available on NPM.

npm install @neotype/prelude

Working with modules

This library provides a suite of ES6 modules. A .js suffix is required in all import statements. All modules provide named exports.

import { cmb, Semigroup } from "@neotype/prelude/cmb.js";
import { cmp, eq, Eq, Ord } from "@neotype/prelude/cmp.js";
import { Either } from "@neotype/prelude/either.js";
import { Maybe } from "@neotype/prelude/maybe.js";
// etc.

See each module's documentation for recommended import practices and available exports.

Inspiration

This library takes inspiration from many existing functional programming languages and libraries, including:

Generated using TypeDoc