go-functional

Functional programming primitives and OTP-inspired concurrency patterns for Go generics.

Go Reference CI

Get started View on GitHub


Installation

go get github.com/mikehelmick/go-functional

Requires Go 1.24+.


Packages at a glance

Functional primitives

Package Highlights
slice Filter, Map, Fold, Find, Zip, Chunk, Sort, Dedup, Scan, Frequencies
maps MapValues, FilterMap, Merge, MergeWith, Invert
optional Maybe[T] — Some or None
result Result[T] — chainable error handling
pipeline Function composition: Pipe, Pipe2, Pipe3, Pipe4

OTP-inspired concurrency

Package Highlights
agent Goroutine-owned mutable state
genserver Serialised request/response loop
task Typed async work with Await / AwaitAll
supervisor Automatic goroutine restart (OneForOne / OneForAll)

Quick look

// Concurrent document processing with OTP building blocks
freqs := agent.New(map[string]int{})

tasks := slice.Map(docs, func(doc string) *task.Task[map[string]int] {
    return task.Run(func() (map[string]int, error) {
        return slice.Frequencies(strings.Fields(doc)), nil
    })
})

results, _ := task.AwaitAll(tasks)
for _, r := range results {
    freqs.Update(func(cur map[string]int) map[string]int {
        for word, n := range r { cur[word] += n }
        return cur
    })
}

See the example application for the full OTP-style word frequency service.


Parts of this library were written with the assistance of Claude Code. © 2026 the go-functional authors. Apache 2.0 License.