What problem does it solve?
samber/mo provides a set of monadic types for Go (Option, Result, Either) to encode absence, failure, and multiple alternatives in a type-safe way, enabling safer data handling and composable pipelines.
Core Features & Use Cases
- Option[T] enables explicit nullable values, preventing nil-pointer panics through typed absence and safe transforms.
- Result[T] captures success/failure as a value and supports short-circuiting through Map/FlatMap, Do notation, and TupleToResult for Go-style errors.
- Either[L,R] models two valid alternatives (e.g., cache vs fresh data) without implying success or failure, with pattern matching via Match or dedicated helpers.
- When to use sub-packages for type-changing transforms, pipeline helpers, and advanced types (Future, IO, State) to build end-to-end data-processing workflows.
- Practical patterns include wrapping stdlib calls with TupleToResult, converting Result to Either for API boundaries, and composing pipelines with option/result/either pipes.
Quick Start
Import the samber/mo library and run a simple example that wraps a nullable value with Option and chains a couple of transformations.