$ show IBM/fp-go
IBM fp-go is a comprehensive functional programming library for Go, heavily inspired by fp-ts (TypeScript). It provides a wide range of algebraic abstractions including Option, Either, Result, IO, Reader, State, Writer, and their monad transformer stacks (IOEither, ReaderIOEither, ReaderIOResult, StateReaderIOEither, etc.). The library employs Go generics to simulate higher-kinded types and includes optics (lenses, prisms, isomorphisms, traversals), lazy iterators, retry policies, resource management via Bracket, dependency injection with Reader, and code generation tools. It also offers idiomatic Go wrappers that return (A, error) tuples while preserving functional composition. The codebase is split into two parallel module paths (root and v2/), with v2 representing a newer generation requiring Go 1.24+ and adding result types, effect packages, and context-aware variants. While highly engineered and feature-rich, the dual tree structure, some incomplete components, and non-standard pragmas introduce maintenance complexity.
The LLM identified 5 files worth highlighting for reuse:
A generic encoding/decoding library built on prisms and isomorphisms, with a validation monad for accumulating errors. It supports bidirectional conversions, alt/bind combinators, and can be extracted for any schema-like data transformation in Go.
A high-level effect monad that combines Reader, IO, and Result into a single type, providing functor, profunctor, filter, retry, traverse, and memoization. It encapsulates dependency injection and error handling in a single composable abstraction, reusable for any Go application needing pure functional effects.
Lazy iterators over Result values (Either[error, A]) with monadic operations, bracket for resource safety, filter, take, traverse, and semigroup/monoid instances. Provides a streaming abstraction that can be reused for any incremental computation with potential failures.
Utilities for type-safe erasure and reification of generic values and functions. Enables heterogeneous collections and erased higher-order functions while preserving type safety through Unerase/SafeUnerase checks. A standalone pattern for bridging Go's generics and any-based APIs.
A generic Builder[T] interface that returns Result[T] with validation logic composed via prisms. Supports partial construction, modification, and final validation. Demonstrates a functional approach to the builder pattern that can be extracted for any object construction pipeline needing validation.