Skip to content

Railway-oriented programming with trcks.oop

Railway-oriented programming (ROP) is a pattern for composing functions that may fail, keeping error handling clean and explicit. This page covers the object-oriented style: you wrap a value in a trcks.oop.Wrapper subclass, chain method calls to transform it, and then unwrap the result — a "wrap → map → unwrap" mental model. Single-track and double-track code are both discussed. Synchronous and asynchronous code are also discussed.

Prerequisites

Overview matrix

Runtime and track Single value Homogeneous tuple
Sync and single-track Wrapper TupleWrapper
Sync and double-track ResultWrapper ResultTupleWrapper
Async and single-track AwaitableWrapper AwaitableTupleWrapper
Async and double-track AwaitableResultWrapper AwaitableResultTupleWrapper
See also

The FP usage page covers the same operations using function composition instead of method chaining.