enum

package
v0.19.19 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package enum provides utilities for implementing exhaustive enumerations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignResult

func AssignResult[T, R any](
	fn func(T) R,
	result *R,
) func(T)

AssignResult returns a function that invokes fn and assigns the result to *result.

func AssignResultErr

func AssignResultErr[T, R any](
	fn func(T) (R, error),
	result *R,
	err *error,
) func(T)

AssignResultErr returns a function that invokes fn and assigns the result and error value to *result and *err, respectively.

func Map

func Map[E Enum, T any](
	v E,
	cases ...T,
) T

Map maps an enum value to a value of type T.

func Range

func Range[E Enum](begin, end E) iter.Seq[E]

Range returns a sequence that yields all values in the inclusive range [begin, end].

func String

func String[E Enum](
	v E,
	cases ...string,
) string

String is a convenience method for implementing fmt.Stringer. It is similar to Map, but does not panic if the enum value is invalid, and does not recurse into v.String().

func Switch

func Switch[E Enum](
	v E,
	cases ...func(),
)

Switch calls a function associated with an enum value.

Types

type Enum

type Enum interface {
	~int
	fmt.Stringer
}

Enum is a constraint for enumeration types.

Jump to

Keyboard shortcuts

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