funcs

package
v0.0.0-...-e28bee9 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: Apache-2.0 Imports: 5 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallerInfo

func CallerInfo(skip int, adjust ...int) (file string, line int, pkg, fname string)

func Error

func Error(args ...any) error

Error provides the last value, which must be of type error. It is expected to be called on the result of a function call providing an error return, whose results should be ignored beside the provided error. e.g.: Error(f())

func ErrorFrom

func ErrorFrom[T any](t T, err error) error

func ErrorFrom2

func ErrorFrom2[T, U any](t T, u U, err error) error

func ErrorFrom3

func ErrorFrom3[T, U, V any](t T, u U, v V, err error) error

func First

func First[T any](v T, rest ...any) T

First returns the first result of a sequence of multiple function results.

func Fourth

func Fourth[T any](a, b, c any, v T, rest ...any) T

Fourth returns the first result of a sequence of multiple function results.

func Last

func Last[T any](args ...any) T

Last returns the last result of a sequence of multiple function results.

func Must

func Must[T any](o T, err error) T

Must expect a result to be provided without error.

func Second

func Second[T any](a any, v T, rest ...any) T

Second returns the second result of a sequence of multiple function results..

func Third

func Third[T any](a, b any, v T, rest ...any) T

Third returns the first result of a sequence of multiple function results.

Types

type Option

type Option[T any] interface {
	// IsNone indicates whether a value is provided or not.
	IsNone() bool
	// Value provides the value of an Option.
	// If no value is provided, a panic is called.
	// It may only be called if IsNone() is false.
	Value() T
	// Error provides an error is IsNone is false.
	Error() error
}

Option represents an optional resuölt of a function. If can represent a result value (of type T) or no result value potentially with an error.

func AndThen

func AndThen[A, B any](a Option[A], f func(A) Option[B]) Option[B]

AndThen chains an operation on a given Option result, for example, if f and g are two operations providing an optional result the AndThen(f(), g) provides a result if f and g provide a result, whereas g is only called and fed with the result of f if f provided a result. Option together with AndThen enables chaining of function calls providing Nil results or error results.

func None

func None[T any](err ...error) Option[T]

None provides an Option without a value, but optionally with an explicit error.

func Some

func Some[T any](v T) Option[T]

Some provides an Option for a given value.

Jump to

Keyboard shortcuts

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