Documentation
Complete API reference and usage guide for GRD - Monadic error handling for Go.
Overview
GRD is a lightweight Go library providing monadic error handling with chainable operations. Eliminate verbose error checking and build readable, composable error-handling pipelines.
🔗 Chainable Operations
Chain multiple operations without explicit error checks
⚡ Zero Dependencies
Pure Go, no external dependencies
🔄 Generic Types
Full type safety with Go generics
🛡️ Error Short-Circuiting
Automatic error propagation through chains
Quick Start
API Reference
Try[T](fn func() (T, error)) *TryResult[T]
Creates a new TryResult from a function that returns a value and error.
Then(fn func(T) (T, error)) *TryResult[T]
Chains another operation. Skipped if previous operation failed.
Catch(fn func(error) T) T
Handles errors and provides fallback value. Always returns a value.
Finally(fn func()) *TryResult[T]
Executes cleanup code regardless of success/failure.
Pattern Comparison
Before (Traditional Go)
After (With GRD)
Best Practices
1. Use meaningful error messages in Catch blocks
Provide context about what operation failed and why.
2. Leverage Finally for cleanup
Use Finally blocks for logging, metrics, and resource cleanup.
3. Keep transformation functions pure when possible
Avoid side effects in Then functions for better testability.
4. Chain related operations for better readability
Group logically related operations in the same chain.
