Functional Programming,
Made Simple.

A TypeScript library that brings functional programming patterns to JavaScript. Result, Maybe, and Unit types for robust, composable code.

example.ts
import { ok, err, some, none, unit } from '@deessejs/fp';

// Result type - handle errors gracefully
const result = ok(42).map((n) => n * 2); // Ok(84)
const failed = err('oops').map((n) => n * 2); // Err('oops')

// Maybe type - handle optional values
const value = some(42).filter((n) => n > 10); // Some(42)
const empty = none<number>().map((n) => n * 2); // None

// Compose with flatMap
const composed = ok(21)
  .flatMap((n) => (n > 10 ? ok(n * 2) : err('too small')));

From optional chaos to typed safety.

Stop relying on undefined checks and type assertions. Get type-safe, composable code that makes debugging a breeze.

before.ts
// Traditional approach
function divide(a: number, b: number): number | undefined {
  if (b === 0) return undefined;
  return a / b;
}

const result = divide(10, 0);
if (result !== undefined) {
  console.log(result);
}
after.ts
// @deessejs/fp approach
import { Result, ok, err } from '@deessejs/fp';

function divide(a: number, b: number): Result<number, string> {
  if (b === 0) return err('Division by zero');
  return ok(a / b);
}

divide(10, 0).match({
  ok: (value) => console.log(value),
  err: (error) => console.error(error),
});

Ready to get started?

Install the package and start building with functional programming patterns today.

Read the docs