railway-oriented · zero-any · functional-typescript

onrails

A lightweight railway-oriented primitive set for TypeScript. Model fallible boundaries, map expected failures, and structure your workflows without exceptions.

import { ,  } from "@onrails/result";
type  =
  | { : "network"; : unknown }
  | { : "not_found" }
  | { : "decode"; : string[] };

// neverthrow-style: replace try/catch around fetch with one typed error channel.
const  = (: string): <, > =>
  (.(), ():  => ({ : "network",  }))
    .(() =>
       === null ? .({ : "not_found" as  }) : .(),
    )
    .();

// Settle once and handle every error in the union — exhaustively, no throws.
const  = (: string) =>
  ().(
    () => ({ : 200, :  }),
    () =>
      . === "not_found"
        ? { : 404, : "No such user" }
        : { : 502, : "Upstream unavailable" },
  );

Railway-Oriented Programming

Tame expected failure paths using type-safe Result, ResultAsync, and Maybe patterns without throwing exceptions across API boundaries.

Strict Type Inference

Fully typed returns and errors. Compatible with TS strict options like noUncheckedIndexedAccess to guarantee robustness.

Expressive Railway Flow

Chain operations using functional composition: pipe, flow, or fluent builders. Write clean nested contexts via railway-do-notation.

No Runtime Bloat

Zero external dependencies at runtime. Thin, pure TypeScript wrappers with maximum optimization and native interop.