Core concepts.
The functional programming ideas behind fp-go — six topics, taught from first principles with Go-specific examples.
The six topics.
| Topic | You learn | Why it matters |
|---|---|---|
Pure functions | Definition, properties, benefits, pure vs impure in Go, practical examplesThe foundation. Easier to test, reason about, compose. | |
Monads | What monads are (and aren't), the monad laws, Option/Either/Result/IO, usage patternsA consistent way to handle effects, errors, optional values — without exceptions or nil checks. | |
Composition | Function composition, Pipe and Flow, point-free style, pipelinesBuild maintainable systems from small, focused functions. | |
Effects & IO | What effects are, lazy evaluation, IO monad, Effect type, separating description from executionExplicit effect management makes code predictable and testable. | |
Higher-kinded types | What HKTs are, why Go lacks them, how fp-go works around it, generic parametersHelps you use fp-go's generic APIs effectively. | |
The Zen of Go | Simplicity, explicit over implicit, composition, error handling, when to use fp-gofp-go enhances Go — it doesn't replace it. |
Learning paths.
1. Pure functions — the basics.
2. Effects & IO — why special types are needed.
3. Composition — building pipelines.
4. Monads — the underlying pattern.
5. The Zen of Go — integrating with Go idioms.
1. Zen of Go — understand the constraints.
2. HKTs — see fp-go's approach.
3. Monads — Go-specific implementations.
4. Effects & IO — lazy evaluation in Go.
Start with The Zen of Go → Pure functions → Composition → Effects & IO → Monads.
Practical examples.
Each concept page includes a three-tab comparison: without fp-go, fp-go v2, fp-go v1.
- Without fp-go
- With fp-go v2
- With fp-go v1
// Standard Go approach
func processUser(id string) (*User, error) {
user, err := fetchUser(id)
if err != nil {
return nil, err
}
validated, err := validateUser(user)
if err != nil {
return nil, err
}
return saveUser(validated)
}
// fp-go v2 approach
func processUser(id string) ioresult.IOResult[User] {
return function.Pipe3(
fetchUser(id),
ioresult.Chain(validateUser),
ioresult.Chain(saveUser),
)
}
// fp-go v1 approach
func processUser(id string) ioeither.IOEither[error, User] {
return function.Pipe3(
fetchUser(id),
ioeither.Chain(validateUser),
ioeither.Chain(saveUser),
)
}HTTP API handlers · database operations · file processing · configuration management · error-handling patterns.
Common questions.
Not if used appropriately. fp-go shines for complex error handling, multiple sequential operations, composability needs, and testing-heavy codebases. For simple cases, standard Go is often better — see The Zen of Go.
Usually no, sometimes yes. Pure functions are often faster (easier to optimize); composition has minimal overhead; IO types add one function call. Use idiomatic packages for performance-critical code.
Start small, show value: use fp-go for new features, demonstrate improved testability and clearer error handling, share success stories, provide training. See Why fp-go?.
You don't need to. Think: Option = "maybe has a value"; Result = "success or error"; IO = "lazy computation". The theory helps but isn't required.
Concept relationships.
Pure Functions ↓ Composition ←→ Effects & IO ↓ ↓ Monads ←──────────┘ ↓ Higher-Kinded Types ↓ The Zen of Go
Pure functions are composable → composition builds pipelines → effects need special handling → monads provide the pattern → HKTs enable generic implementations → the Zen of Go guides usage.
Prerequisites
Basic Go syntax.
Functions and closures.
Interfaces.
Generics (Go 1.18+).
These guides assume no prior functional programming knowledge. Concepts are taught from first principles with Go examples.
Summary
- Pure Functions — predictable, testable code
- Monads — pattern for sequencing with context
- Composition — building from simple pieces
- Effects & IO — explicit side effect management
- Higher-Kinded Types — generic abstractions
- The Zen of Go — idiomatic usage
You don't need to understand all the theory to use fp-go effectively. Start with practical patterns and deepen your understanding over time.