Skip to content

Introduction

OOFP (Object-Oriented Functional Programming) is a TypeScript library ecosystem for building type-safe applications using functional programming patterns. It provides algebraic data types, composition utilities, and real-world patterns that scale from small utilities to large production applications.

TypeScript applications commonly suffer from:

  • Untyped errorstry-catch loses type information about what can go wrong
  • Implicit dependencies — Functions reach into global state or closures for their dependencies
  • Nullable chaosnull and undefined propagate silently through code
  • Callback hell — Async operations become deeply nested and hard to follow

OOFP provides algebraic data types that make these problems impossible:

ProblemOOFP SolutionType
Nullable valuesMaybe — values that may or may not existMaybe<A>
Operations that can failEither — typed success or failureEither<E, A>
Async operationsTask — lazy async computationTask<A>
Async + failureTaskEither — async that can failTaskEither<E, A>
Dependency injectionReader — function that needs contextReader<R, A>
DI + async + failureReaderTaskEither — the ultimate monadRTE<R, E, A>
  1. Type safety first — No any, no type assertions, full inference
  2. Composition over inheritance — Everything composes with pipe and flow
  3. Laziness — Computations describe what to do, not when to do it
  4. Execute at boundaries — Build pure pipelines, run them at HTTP handlers or CLI entry points
  5. Zero dependencies — No runtime dependencies, tree-shakeable imports

OOFP is a monorepo with 5 packages:

  • @oofp/core — Foundation: all monads, composition, collections, type classes
  • @oofp/http — HTTP client built on ReaderTaskEither
  • @oofp/query — Query cache with TTL and invalidation
  • @oofp/saga — Saga pattern for transactional workflows
  • @oofp/react — React hooks (experimental)

OOFP is inspired by fp-ts and the Fantasy Land Specification, with a focus on practical usability and real-world patterns over theoretical purity.