Skip to content
Pyrula

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, Try

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.

  • Either holds a value or an error. A typed error channel without exceptions.
  • Validated is like Either but accumulates every error instead of stopping at the first.
  • Option is present or absent, with no None ambiguity.
  • Try captures a result or the exception that broke it.
  • Collections: IList, IMap, and ISet are immutable and structurally shared, so copies are cheap.
  • NonEmptyList is a list that can never be empty, so head and reduce are total.
  • Numeric lists are compact, typed lists for int and float data.
  • 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 timedelta interop.
  • 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.

The Quickstart runs Either and Option end to end.