Code-Memo

Functional programming in Go

Go is not a purely functional language: there is mutable state, loops are idiomatic, and generics arrived late. Still, first-class functions, closures, and immutability as a habit cover many FP patterns.

First-class functions

Pass functions as arguments, return them from functions, store in variables and struct fields.

Immutability habits
Higher-order slice operations

Before generics, sort, strings.Map, and hand-rolled helpers were common. With generics, small Map/Filter utilities are easier — but a plain for loop is often clearest.

Monads / Option types

Go uses error instead of Maybe for many fallible operations. For optional values, use pointers, , ok patterns, or a small generic Option[T] type if your codebase agrees on it.

Pipelines

Function composition + channels can model pipelines; keep stages explicit to avoid goroutine leaks.

Referential transparency

Pure functions (same inputs → same outputs, no I/O) are easy to test. Push I/O to the edges of packages.