golang-samber-mo

Implement monadic types in Go using samber/mo for type-safe nullable values and error handling.

1|Updated Feb 2, 2026
One-click install
npx skills add https://github.com/rockcookies/skills --skill golang-samber-mo-rockcookies
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-samber-mo
Source: https://github.com/rockcookies/skills/tree/main/skills/samber-golang/golang-samber-mo
Command: npx skills add https://github.com/rockcookies/skills --skill golang-samber-mo-rockcookies

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Go's idiomatic error handling requires repetitive if err != nil checks, and nil pointers cause runtime panics that the type system cannot prevent. This Skill teaches how to use the samber/mo library to make absence and failure explicit in Go types, replacing nil checks with Option[T] and error tuples with composable Result[T] pipelines. ## Core Features & Use Cases - Option[T] for nullable values: Eliminate nil pointer risks in JSON API responses and database models, since Option implements json.Marshaler, sql.Scanner, and driver.Valuer natively. - Result[T] and Either[L, R] for error handling: Convert Go's (T, error) tuples with TupleToResult, chain operations with Map/FlatMap, and use Either when both outcomes are valid alternatives. - Pipeline sub-packages and Do notation: Work around Go's limitation where methods cannot change type parameters by using option.Pipe3, result.Pipe2, or mo.Do for multi-step type-changing transformations. - Use Case: You are building a config loader that reads a file, parses YAML, and validates the result. Use mo.TupleToResult at the boundary, chain with result.Pipe2 for type-changing steps, and extract with OrElse at the end. ## Quick Start Ask the AI to refactor a Go function that returns (T, error) into a samber/mo Result pipeline using TupleToResult and FlatMap chaining.

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 samber/mo Option for nullable database fields in Go?▼

Use mo.Option[string] directly in your struct for nullable columns. Option implements sql.Scanner and driver.Valuer for database scanning, plus json.Marshaler and json.Unmarshaler so the same struct works for JSON API responses without custom serialization code.

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

Result[T] represents success or failure where the error side is always an error type, equivalent to Either[error, T]. Either[L, R] is for two valid alternatives like cached versus fresh data, where neither side implies failure.

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

Go methods cannot introduce new type parameters, so Option[T].Map can only return Option[T]. For type-changing transforms like Option[int] to Option[string], use the curried option.Map function from the github.com/samber/mo/option sub-package.

How do I convert Go's (T, error) return values to samber/mo Result?▼

Use mo.TupleToResult to wrap any (T, error) tuple directly, such as mo.TupleToResult(os.ReadFile(path)). For functions that may also panic, use mo.Try which catches both returned errors and panics into a Result.

When should I not use monads in Go?▼

Avoid monads for simple one-step operations where if err != nil is clearer, in performance-critical hot paths, and 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-style code in a Result, catching panics from MustGet() calls and converting them to Err. Use it when FlatMap chaining becomes deeply nested and you want straight-line code with automatic error propagation.