go-samber-mo

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

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill go-samber-mo-asarchami
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-samber-mo
Source: https://github.com/asarchami/dotfiles/tree/main/dot_claude/skills/go-samber-mo
Command: npx skills add https://github.com/asarchami/dotfiles --skill go-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 idiomatic error handling requires repetitive if err != nil checks, and nil pointers can cause runtime panics that the type system cannot prevent. This Skill provides guidance for using samber/mo's monadic types (Option, Result, Either, Future, IO, Task, State) to make absence and failure explicit at the type level and compose operations into pipelines. ## Core Features & Use Cases - Option[T] for nullable values: Replace nil pointers with Some/None semantics, with built-in JSON marshaling and sql.Scanner/driver.Valuer support for database models. - Result[T] and Do notation: Convert Go's (T, error) tuples into chainable Results with automatic error short-circuiting via Map, FlatMap, and mo.Do. - Pipeline sub-packages: Use option/result/either Pipe functions for type-changing transformations that Go's method type parameters cannot express. - Use Case: When building a config loader that reads a file, parses YAML, and validates the result, chain the steps with result.Pipe2 so errors propagate automatically instead of writing three separate error checks. ## Quick Start Ask the AI to refactor a Go function that returns (value, error) into one that uses samber/mo Result types with a chained pipeline.

Frequently Asked Questions about go-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 values with mo.Some or mo.None, extract safely with OrElse, and transform with Map. Option implements json.Marshaler and sql.Scanner, so it works directly in JSON structs and database models.

How to chain error handling in Go with samber/mo Result?

Convert Go's (T, error) tuples with mo.TupleToResult, then chain operations with Map and FlatMap so errors short-circuit automatically. For imperative-style code, wrap MustGet calls inside mo.Do, which catches panics and returns them as Err values.

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

Result[T] is specialized for success/failure where the error side is always an error type. Either[L, R] represents two valid alternatives, such as cached versus fresh data, where neither side implies failure. Use Result for fallible operations and Either for discriminated unions.

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 or option.Pipe3, which are standalone generic functions.

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

Yes. Option implements sql.Scanner and driver.Valuer for nullable database columns, plus json.Marshaler/Unmarshaler where Some serializes to the value and None to null. It also supports Go 1.24's omitzero tag to omit None fields from JSON output.

When should I avoid using monads in Go?

Stick with plain Go for simple one-step operations where if err != nil is clear enough, performance-critical hot paths where monad allocation overhead matters, and teams unfamiliar with functional programming concepts where explicit error handling is more readable.