Introduction
Welcome to onrails, the railway-oriented programming toolkit for TypeScript.
Welcome to the onrails documentation.
onrails is a lightweight, pure TypeScript library providing algebraic primitives like Result (Ok/Err), ResultAsync, and Maybe (Some/None) along with pattern matching via @onrails/pattern.
Key Goals
- Tame Expected Failure: Make fallible boundaries clean and inspectable.
- No Throws: Avoid throwing exceptions for normal control paths.
- Compile-Time Safety: Strict type inference and exhaustive matching.
Explore
Getting Started
Install the primitives and write your first railway-oriented flow.
Recipes
Composition patterns — pipe/flow, generator do-notation, and the Railway builder.
Result
Ok / Err, ResultAsync, and the dual-form function API.
Maybe
Some / None for expected absence.
Pattern
Exhaustive match over tagged unions.
vs neverthrow
The closest neighbour — same railway idea, different data model.