fp-go is a functional programming library for Go 1.24+ developed by IBM that brings functional programming patterns to Go through generic type aliases and composable APIs. The library is heavily inspired by fp-ts, a popular TypeScript functional programming library, and aims to make it easier to write maintainable and testable code by encouraging pure functions, side effect isolation, and consistent composition patterns across data types.
The core of fp-go provides several key monadic data types that enable functional composition. These include Option for representing optional values, Either for handling computations that can fail with an error or succeed with a value, IO for lazy computations, IOEither for lazy computations that can fail, Reader for computations dependent on an environment, ReaderIOEither for combining reader, IO, and Either capabilities, Task for asynchronous computations, and State for stateful computations. All these data types support common monadic operations like Map for transforming values, Chain for flatMapping, Ap for applying functions in context, Of for wrapping values, and Fold for extracting values.
The library explicitly aligns itself with the Zen of Go principles, demonstrating how functional programming patterns can coexist with Go's philosophy. Each top-level package fulfills a single purpose by defining one data type and its operations. The library handles errors explicitly through the Either type, encourages returning early rather than nesting deeply through small focused functions, and avoids package-level state entirely. It also provides optics including Lens, Prism, and Traversal for immutable data manipulation, supporting Functor, Applicative, and Monad abstractions with do-notation-style programming.
The implementation leverages Go's generics system for type safety, though this comes with the tradeoff of potentially larger binaries due to different versions per type. The library addresses Go's lack of native higher-kinded types by introducing HKTs as individual types and implementing generic algorithms in internal packages to keep complexity hidden from end-users. Generic subpackages are available for library extensions, while main packages specialize generic implementations for convenience.
According to GitGenius activity tracking, the repository shows median issue and pull request response latency of 123.7 hours with a mean of 1019.8 hours across tracked items. The most active contributors include CarstenLeue with 6 tracked events and Ocramius with 3 events. The repository overlaps with contributors from other projects including ocramius/proxymanager, meteor/meteor, and apollographql/apollo-client, indicating cross-pollination with other functional programming and web development communities.
The library provides conversion utilities to bridge between idiomatic Go and functional styles, including Eitherizerize functions for converting idiomatic Go functions to functional style and Uneitherizerize functions for the reverse conversion. This makes it practical for integrating functional patterns into existing Go codebases. The repository includes code samples and comprehensive API documentation, with version 2 specifically requiring Go 1.24 and leveraging the latest generic capabilities available in that release.