A Go library providing functional-style iterators and consumers to augment the standard library's iter.Seq.
go-functional is a Go library that provides a comprehensive set of functional-style iterator utilities to augment the standard library's iter.Seq type. It solves the problem of verbose and imperative data processing by offering chainable and standalone operations like filtering, mapping, folding, and collecting, enabling more declarative and expressive code when working with sequences of data.
Go developers (1.23+) who work with iterators (iter.Seq) and want to write more functional, declarative, and concise data processing pipelines, especially those dealing with slices, maps, channels, or streams.
Developers choose go-functional because it provides a rich, idiomatic, and type-safe functional programming layer on top of Go's native iterators, with both a convenient chainable API (itx) and standard library-compatible functions (it), all without requiring external dependencies.
go-functional is a library of iterators to augment the standard library
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
The itx package allows fluent dot-chaining like .Filter().Take().Collect(), making pipelines readable and concise, as shown in examples for processing natural numbers.
Functions like TryCollect and MustCollect handle errors within iterator chains gracefully, reducing boilerplate when working with error-prone sources like io.Reader.
It provides a comprehensive set of operations including infinite iterators (NaturalNumbers), adapters for slices/maps/channels, and consumers like Fold and Find, covering most FP needs.
The it package uses iter.Seq types for seamless compatibility with Go's slices and maps packages, allowing mixed usage without friction.
Due to Go's generics constraints, the chainable itx package lacks key operations like Map, Zip, and All, forcing users to use workarounds or drop back to the non-chainable it package.
Iterators like Cycle and FilterUnique store all yielded values in memory, which can lead to high memory usage with large or infinite sequences, as warned in the README.
Maintaining two packages (it and itx) with overlapping but incomplete feature sets can confuse users about which to use and when, increasing cognitive load.