samber-mo

Implements Option, Result, and Either monads in Go using the samber/mo library.

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill samber-mo-asarchami
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: samber-mo
Source: https://github.com/asarchami/dotfiles/tree/main/dot_config/opencode/skills/samber/samber-mo
Command: npx skills add https://github.com/asarchami/dotfiles --skill samber-mo-asarchami

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires github.com/samber/mo, and includes references (resource) components.

What problem does it solve? Go's nil pointers and repetitive (T, error) checks cause runtime panics and verbose error handling. This Skill guides the use of samber/mo monads so absence and failure become type-level values that compose through pipelines instead of manual if/else checks. ## Core Features & Use Cases - Monad Selection Guidance: Choose between Option, Result, Either, Either3-5, Future, IO, Task, and State based on whether a value is absent, an operation is fallible, or both branches are valid alternatives. - Boundary Wrapping: Convert Go's (T, error) and (V, bool) tuples with TupleToResult and TupleToOption at API boundaries, then chain Map/FlatMap/OrElse pipelines inside domain code. - Type-Changing Pipelines: Work around Go's generic method limitation using sub-package functions (option.Map, result.Pipe3) when a transformation changes the type parameter. - Use Case: When reviewing a Go service that returns nullable database fields, wrap columns in mo.Option[string] (which implements sql.Scanner and driver.Valuer) and audit for MustGet calls outside mo.Do blocks. ## Quick Start Ask the assistant to refactor a Go function that returns (T, error) into a samber/mo Result pipeline with TupleToResult at the boundary.

Frequently Asked Questions about samber-mo

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle nullable values in Go without nil pointers?

Use mo.Option[T] from samber/mo to represent values that may be absent. Wrap pointers with mo.PointerToOption, extract safely with OrElse or OrEmpty, and transform with Map or FlatMap so absence propagates without nil checks.

What is the difference between Result and Either in samber/mo?

Result[T] represents an operation that may fail and is equivalent to Either[error, T]. Either[L, R] is for two valid alternatives where neither side is an error, such as cached versus fresh data. Use Result for success/failure and Either for genuine alternatives.

Why can't Option.Map change the type parameter in Go?

Go methods cannot introduce new type parameters, so Option[T].Map only returns Option[T]. For type-changing transforms like Option[int] to Option[string], use the sub-package functions option.Map, result.Map, or Pipe1 through Pipe10 pipelines.

Does samber/mo Option work with JSON and SQL databases?

Yes. Option implements json.Marshaler/Unmarshaler, sql.Scanner, and driver.Valuer, so it can be used directly in JSON structs and database models for nullable columns. It also supports Go 1.24's omitzero tag to omit None values.

When should MustGet be avoided in samber/mo?

MustGet panics on None or Err, so it should only be called inside mo.Do, which catches the panic and converts it to an Err result, or where presence is provably guaranteed. Prefer OrElse for safe extraction on fallible paths.

When should I use plain Go error handling instead of monads?

Plain Go is better for simple one-step operations where a single if err != nil is clear, performance-critical hot paths where monad allocation overhead matters, or when each step needs explicit error inspection and recovery logic.