A collection of functional programming helpers for Go, leveraging generics to provide common utilities like map, filter, reduce, and monadic types.
fp-go is a functional programming library for Go that provides a collection of utilities like map, filter, reduce, and monadic types such as Option and Either. It leverages Go 1.18+ generics to offer type-safe operations, enabling developers to write more declarative and composable code in a language traditionally focused on imperative styles.
Go developers interested in functional programming patterns, those looking to write more declarative and composable code, and teams adopting generics for type-safe abstractions.
It offers a pragmatic, idiomatic way to use functional programming in Go with automatic currying, flexible callback variations, and monadic types, reducing boilerplate and improving code expressiveness compared to manual implementations.
fp-go is a collection of Functional Programming helpers powered by Golang 1.18+ generics.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Functions are curried by default with data-last parameters, enabling partial application and composition without extra setup, as shown in the Filter example where filterPositive is created by currying.
Offers default, WithIndex, and WithSlice variants for helpers like Map and Filter, providing access to index and full slice when needed, which enhances adaptability for complex operations.
Leverages Go 1.18+ generics to ensure compile-time type safety in operations like Map and Reduce, reducing runtime errors compared to older interface-based approaches.
Implements Option and Either types for handling optional values and errors functionally, offering a declarative alternative to Go's traditional error patterns with methods like Match and GetOrElse.
Requires Go 1.18+ generics, making it incompatible with older Go versions or projects stuck in legacy environments, which limits adoption in certain codebases.
The functional abstractions, such as currying and monadic wrappers, can introduce additional function calls and allocations, potentially slowing down performance-critical loops compared to direct imperative code.
Compared to comprehensive FP libraries in other languages, it lacks advanced constructs like functors, applicatives, or monad transformers, which might be necessary for complex functional programming scenarios.