Skip to content

DeesseJS FP

Handle failures and missing values explicitly.

Result and Maybe for TypeScript. Make success, failure and absence part of your types, then compose the next step.

Installation audience
npm install @deessejs/fp
parse-age.ts
import { ok, err, type Result } from '@deessejs/fp';

function parseAge(input: string): Result<number, string> {
  const age = Number(input);
  return input.trim() !== '' && Number.isInteger(age) && age >= 0
    ? ok(age)
    : err('Enter a valid age');
}

parseAge('22').match({
  ok: (age) => `Age: ${age}`,
  err: (error) => error,
});
ResultparseAge('22') → Age: 22parseAge('') → Enter a valid age

Why FP

Make every outcome visible.

Keep the successful path readable, without leaving failures or missing values implicit.

Handle failure

Return a success or an error. Keep the failure visible in the type and handle both outcomes where they matter.

Read the guide

Handle absence

Represent a value that might be missing. Transform it when present and choose a fallback when absent.

Read the guide

Compose safely

Chain transformations with map and flatMap. Continue on success and preserve the first failure along the way.

Read the guide

Before & after

Same task. Explicit outcomes.

Compare ordinary TypeScript with FP on a small, complete example. Choose the representation that fits your code.

Both versions handle division by zero. Result carries the reason for failure in its return type.

TypeScript
function divide(a: number, b: number): number | undefined {
  if (b === 0) return undefined;
  return a / b;
}

const result = divide(10, 0);
const message = result !== undefined
  ? String(result)
  : 'Division by zero';
With @deessejs/fp
import { ok, err, type Result } from '@deessejs/fp';

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

const message = divide(10, 0).match({
  ok: (value) => String(value),
  err: (error) => error,
});

The primitives

API reference

Small types. Clear contracts.

Start with Result and Maybe. Use Unit when a function needs an explicit value for an otherwise empty return.

Result<T, E>

Result

A success carrying T or a failure carrying E. Transform either branch and handle the outcome with match.

Explore Result
Maybe<T>

Maybe

A present value or none. Map the value, chain another lookup or provide an explicit fallback.

Explore Maybe
Unit

Unit

A single value for an operation with no meaningful return value. It does not manage or isolate side effects.

Explore Unit

Get started

Make the next outcome explicit.

Install the package and start with Result or Maybe. Explore the API as you need it.

Read the docs
npm install @deessejs/fp