FP
UTILS

fp is a lightweight TypeScript library designed to simplify functional programming by providing essential types like Option and Result. It helps developers handle errors, manage optional values, and write expressive, composable code.

Installation

$ pnpm add @carbonteq/fp
Hero illustration

But Why FP?

In TypeScript, the “happy path” is easy — it’s the nulls, undefineds, and errors that quietly add boilerplate. @carbonteq/fp gives you small, focused primitives (like Option and Result) so you can model uncertainty and failure explicitly without rewriting everything around a new runtime.

If you’re already using Effect, fp is the “grab-bag” tier: similar ergonomics for everyday data-flow, but with less setup when all you want is typed composition around values.

With @carbonteq/fp
import {  } from "@carbonteq/fp";

type  = { : string; : boolean };
declare const :  | null;

const  = .()
  .(() => .)
  .(() => .)
  .("unverified@example.com");

.(email);
const email: string
Effect-style
import {  } from "effect/Function";
import * as  from "effect/Option";
import * as  from "effect/Effect";

type  = { : string; : boolean };
declare const :  | null;

const  = .(() =>
  (
    .(),
    .(() => .),
    .(() => .),
    .(() => "unverified@example.com"),
  ),
);

const  = .();

.(email);
const email: string

What you get

Sync + async, one flow

Write the same pipeline whether steps are synchronous or asynchronous. Compose transformations, validations, and fallbacks without splitting your codebase into “sync” and “async” versions.

  • Chain sync + async steps
  • Keep types consistent end-to-end
  • Stay readable as complexity grows

Tiny footprint

Get the ergonomics you need without pulling in a whole ecosystem. fp is intentionally small so you can adopt it incrementally — per function, per module, per service.

  • Minimal API surface
  • Small bundle size
  • Easy incremental adoption

Never try & catch again

Model failure explicitly with Result and keep the happy path clean. Handle errors where they matter, with types guiding what you’ve covered (and what you haven’t).

  • Type-safe errors & values
  • Combinators for recovery
  • No hidden thrown exceptions

Safer code, simpler flow

Doing the right thing in TypeScript is hard. fp makes it easier by giving you small, predictable primitives.

  • Handle errors, async code, concurrency and streams with composable primitives.
  • Reduce one-off dependencies by leaning on a coherent core.
  • Integrates cleanly with your existing stack.
Type safety: errors are part of the signature
With FP Library
import {  } from "@carbonteq/fp";

type  = { : string };
type  = "NotFound" | "DbDown";

declare function (: string): <, >;
declare const : string;

const user = ();
const user: Result<User, GetUserError>
Without FP Library
type  = { : string };

declare function (: string): ;
declare const : string;

// what can this throw? you have to read the code
const user = ();
const user: User
© 2023 CarbonTeq. All rights reserved.