types

package
v0.14.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2025 License: MIT Imports: 0 Imported by: 0

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

func Return[In any, T any](t T) func(In) T

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

func Return0

func Return0[T any](t T) func() T

Return0 creates a zero-argument function that always returns t. Useful for lazy defaults or callbacks that require func() T.

Example:

f := types.Return0(10)
fmt.Println(f()) // 10

func Value

func Value[T any]() (t T)

Value returns the zero value of type T. Use when you need an explicit zero value without constructing it manually.

Example:

var s string = types.Value[string]() // s == ""

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL