Object-Oriented Functional Programming ecosystem for TypeScript. A collection of libraries that bring algebraic data types, monadic composition, and type-safe functional patterns to real-world TypeScript applications.
| Package | Version | Description |
|---|---|---|
@oofp/core |
Foundation library -- Maybe, Either, Task, TaskEither, Reader, ReaderTaskEither, State, pipe, flow, compose, curry, and more | |
@oofp/http |
Functional HTTP client built on ReaderTaskEither with interceptors, retry, and structured errors | |
@oofp/query |
Query and cache library with tag-based invalidation, request deduplication, and telemetry | |
@oofp/saga |
Saga pattern for distributed transactions with automatic compensations | |
@oofp/react |
Functional React components using Reader monads (experimental) |
# Install individual packages
npm install @oofp/core
npm install @oofp/http
npm install @oofp/query
npm install @oofp/saga
npm install @oofp/reactAll packages except @oofp/core have it as a peer dependency. Install @oofp/core first, then add the packages you need.
import { pipe } from '@oofp/core/pipe'
import * as RTE from '@oofp/core/reader-task-either'
import * as E from '@oofp/core/either'
import { get } from '@oofp/http/client'
import { withBearer } from '@oofp/http/interceptors'
interface AppContext {
baseUrl: string
headers: Record<string, string>
timeout: number
}
const fetchUser = (id: number) =>
pipe(
get<User>(`/users/${id}`, {
contextInterceptors: [withBearer('my-token')],
}),
RTE.map(user => ({ ...user, fullName: `${user.firstName} ${user.lastName}` })),
)
const ctx: AppContext = {
baseUrl: 'https://api.example.com',
headers: {},
timeout: 5000,
}
const result = await fetchUser(123)(ctx)()
if (E.isRight(result)) {
console.log(result.value.fullName)
}oofp/
packages/
core/ @oofp/core
http/ @oofp/http
query/ @oofp/query
saga/ @oofp/saga
react/ @oofp/react
This is a pnpm workspace monorepo. Versioning and publishing are managed with Changesets.
# Clone and install
git clone https://github.com/thexpert507/oofp.git
cd oofp
pnpm install
# Build all packages
pnpm build
# Run all tests
pnpm test
# Type check all packages
pnpm type-check
# Lint
pnpm lint
# Format
pnpm format# Build a specific package
pnpm --filter @oofp/core build
# Test a specific package
pnpm --filter @oofp/saga test
# Watch tests
pnpm --filter @oofp/http test:watchContributions are welcome. Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature) - Commit your changes
- Push to the branch
- Open a Pull Request
Use pnpm changeset to create a changeset for your changes before submitting.
This project is licensed under the MIT License.