Skip to content

Practical helpers to unfunctionalize fp-ts types

License

Notifications You must be signed in to change notification settings

jdolle/unfun-ts

Repository files navigation

unfun-ts

Maintainability Test Coverage CircleCI

Practical helpers to unfunctionalize fp-ts types

Description

Functional programming is powerful, but not always the most practical. This package encourages using functional programming in Typescript using fp-ts by providing a very practical way to interact with the broader, imperative codebase.

Install

unfun-ts is a utility library for fp-ts. Therefore fp-ts is a peer dependency of unfun-ts.

yarn add unfun-ts
yarn add fp-ts@^2.0.0

Usage

import * as UE from "unfun-ts/lib/Either";
import * as E from "fp-ts/lib/Either";
import { pipe } from "fp-ts/lib/pipeable";

// const nullyValue: undefined | number;
try {
  const value = pipe(
    nullyValue,
    E.fromNullable("nully"),
    UE.getOrThrow(),
  );
} catch (bad) {
  console.error(`The value was ${bad}`);
}