golang-samber-mo

Implements monadic types like Option, Result, and Either for type-safe Go error handling.

Updated Jun 30, 2026
One-click install
npx skills add https://github.com/santoshkal/chezmoi --skill golang-samber-mo-santoshkal
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-samber-mo
Source: https://github.com/santoshkal/chezmoi/tree/main/private_dot_config/opencode/skills/Golang/skills/golang-samber-mo
Command: npx skills add https://github.com/santoshkal/chezmoi --skill golang-samber-mo-santoshkal

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go developers face repetitive nil checks and verbose if-err handling when chaining fallible operations. This Skill provides guidance for using samber/mo monadic types to make nullable values and error propagation explicit at the type level. ## Core Features & Use Cases - Option[T] for nullable values: Replace nil pointers with Some/None semantics, with built-in JSON marshaling and SQL Scanner/Valuer support for database models. - Result[T] and Either[L, R] for error handling: Chain fallible operations with Map, FlatMap, and Pipe functions so errors short-circuit automatically without nested if/else blocks. - Advanced types and pipelines: Use Future, Task, IO, and State for async and stateful computations, plus sub-package Pipe functions for type-changing transformations. - Use Case: When building a config loader that reads a file, parses YAML, and validates the result, wrap each step with mo.TupleToResult and compose them via result.Pipe2 so any failure propagates cleanly to a single Err value. ## Quick Start Ask the AI to refactor a Go function that chains multiple fallible operations using samber/mo Result types and pipeline composition.

Frequently Asked Questions about golang-samber-mo

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

FAQPage Schema
How do I use Option instead of nil pointers in Go?▼

Use mo.Some(value) for present values and mo.None[T]() for absent ones, then extract safely with OrElse or transform with Map. Option implements json.Marshaler and sql.Scanner, so it works directly in JSON structs and database models without custom serialization code.

How do I chain type-changing transformations with samber/mo?▼

Use sub-package functions like option.Map or result.Map from github.com/samber/mo/option and github.com/samber/mo/result, because Go methods cannot introduce new type parameters. For multi-step pipelines, use Pipe functions such as option.Pipe3 to compose transformations left-to-right.

When should I use Either instead of Result in Go?▼

Use Result[T] when one path is an error and the other is success. Use Either[L, R] when both outcomes are valid alternatives, such as cached versus fresh data, since neither side implies failure.

Does samber/mo Option work with database nullable columns?▼

Yes, Option implements sql.Scanner and driver.Valuer, so you can scan nullable columns directly into mo.Option[string] fields and pass them to db.Exec for inserts. This eliminates the need for separate DTO structs or sql.NullString conversions.

When should I avoid using monads in Go?▼

Avoid monads for simple one-step operations where if err != nil is clearer, in performance-critical hot paths where allocation overhead matters, or when your team is unfamiliar with functional patterns. Result shines with multi-step chains, not single operations.

What is mo.Do and when should I use it?▼

mo.Do wraps imperative code in a Result, catching panics from MustGet calls and converting them to Err values. Use it when FlatMap chaining becomes deeply nested and you want straight-line code with automatic error propagation.