Documentation
¶
Overview ¶
Package types. map provides small, generic functional helpers inspired by functional programming patterns. These utilities are designed to make higher‑order function composition and default handling more expressive.
Avoid them when plain inline functions are clearer — Go favors explicitness, so these helpers are most useful in generic libraries or when building composable abstractions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compose ¶
func Compose[T, U, V any](fn1 func(T) U, fn2 func(U) V) func(T) V
Compose chains two functions: fn1 followed by fn2. Returns a new function that applies fn1, then fn2.
Example:
f := types.Compose(strings.TrimSpace, strings.ToUpper)
fmt.Println(f(" hi ")) // "HI"
func Id ¶
func Id[T any](t T) T
Id returns its input unchanged. Useful as a default function or placeholder in higher-order contexts.
Example:
x := types.Id(42) // x == 42
func Return ¶
Return creates a function that ignores its input and always returns t. Use when you need a constant function of type func(In) T.
Example:
f := types.Return
fmt.Println(f("ignored")) // 5
Types ¶
This section is empty.