Primitives
The core is a small set of typed values implemented in Rust through PyO3. They’re the stable base everything else builds on, and they read like plain Python.
from pyrula import Either, Option, TryInspired by Scala
Section titled “Inspired by Scala”These types come from Scala’s standard library. Either, Option, and Try carry the
same cases and methods (map, flat_map, fold, get_or_else, recover); IList and
IMap are immutable and structurally shared like Scala’s List and Map; @sealed and
@case with match are Scala’s sealed trait plus case class; and
do-notation is Scala’s for-comprehension. If you know the
Scala versions, these read the same, just snake_cased for Python. Each page below ends with
the Scala equivalent where there is a direct one.
The types
Section titled “The types”- Either holds a value or an error. A typed error channel without exceptions.
- Validated is like
Eitherbut accumulates every error instead of stopping at the first. - Option is present or absent, with no
Noneambiguity. - Try captures a result or the exception that broke it.
- Collections:
IList,IMap, andISetare immutable and structurally shared, so copies are cheap. - NonEmptyList is a list that can never be empty, so
headandreduceare total. - Numeric lists are compact, typed lists for
intandfloatdata. - IntSet is an immutable integer set backed by a Roaring bitmap, for fast bulk set algebra over ID-like data.
- Duration is a typed time span with arithmetic and
timedeltainterop. - serde handles typed encode and decode across the boundary.
Either, Validated, Option, and Try are real generics: Either[A, E], Option[A], etc.
type-check, and their cases (Ok/Err, Some/Nothing, Success/Failure,
Valid/Invalid) are subtypes, so isinstance(x, Either) holds.
Working with them
Section titled “Working with them”- Modeling with
@casevalue classes. - Composition and do-notation chain
EitherandOptionwithout nesting the checks. - Examples show the types combined on small real-world tasks.
The Quickstart runs Either and Option end to end.