golang-samber-mo

Replace nil checks and error propagation with samber/mo monadic composition in Go.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps Go developers replace unsafe nil handling and repetitive error-checking with type-safe monadic composition using samber/mo, reducing runtime panics and control-flow boilerplate.

Core Features & Use Cases

  • Option[T] for absence without nil: model nullable values (e.g., optional config, missing cache entries, nullable DB fields) so callers handle None explicitly.
  • Result[T] for composable error handling: represent success/failure and chain transformations while errors short-circuit automatically.
  • Either[L,R] for two valid alternatives: represent cases where neither outcome is inherently an error (e.g., cached vs fresh data).
  • Pipeline sub-packages for type-changing steps: use option/, result/, and either/ functions when chaining changes types across steps.
  • Do notation and MustGet safety: write imperative-style code inside mo.Do where MustGet panics are caught and converted into Result errors.
  • Serialization + DB friendliness: use Option in JSON and as sql.Scanner/driver.Valuer for nullable columns without separate DTOs.

Quick Start

Ask the AI to show how to refactor a Go function to return mo.Option or mo.Result and demonstrate a safe pipeline with option.Map/FlatMap or mo.Do.

Frequently Asked Questions about golang-samber-mo

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

FAQPage Schema
How do I handle nil values in Go without writing repetitive nil checks?

To handle nil values safely, use the Option monad from samber/mo to model nullable fields like optional config or missing cache entries. This forces callers to handle absence explicitly, eliminating runtime panics from unchecked nil dereferences.

What's the best way to chain error handling in a Go pipeline without manual if-err checks?

The best way to chain error handling is using the Result monad from samber/mo, which represents success or failure and automatically short-circuits transformations when an error occurs, removing manual if-err control-flow boilerplate.

How does the Either monad work for representing two valid alternatives in Go?

The Either monad works by wrapping two valid outcomes, Left and Right, where neither is inherently an error. It models cases like cached versus fresh data across API boundaries and internal domain logic without treating one side as a failure.

Can I use samber/mo Option with JSON serialization and nullable database columns?

Yes, samber/mo Option works directly with JSON serialization and implements sql.Scanner and driver.Valuer. This allows you to map nullable database columns and optional API fields without creating separate Data Transfer Objects.

Does samber/mo support imperative-style error capture instead of pure functional chaining?

Yes, samber/mo supports imperative-style code via mo.Do. MustGet panics thrown inside this block are safely caught and converted into standard Result errors, allowing safe imperative composition without pure functional chaining.