Functional Programming,
Made Simple.
A TypeScript library that brings functional programming patterns to JavaScript. Result, Maybe, and Unit types for robust, composable code.
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')));Features
Everything you need for robust functional programming in TypeScript.
Result Type
Handle errors with type-safe success and failure states. No more undefined/null checks everywhere.
Maybe Type
Work with optional values in a composable way. Explicitly handle the absence of values.
Unit Type
Represent intentional void returns for side effects. Makes side effects explicit in your type signatures.
TypeScript Native
Full type safety with generic types. Leverage TypeScript to catch errors before they happen.
Error Handling
Type-safe error propagation with the Result type.
Optional Values
Handle null/undefined with the Maybe type.
API Reference
Complete API documentation with examples.
From optional chaos to typed safety.
Stop relying on undefined checks and type assertions. Get type-safe, composable code that makes debugging a breeze.
// 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);
}// @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.