legacy

package
v2.12.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cast

func Cast[X any, Y any](x X) Y

Cast converts an element of type X to an interface of type Y.

For example, slices.Map(ks.Cast[*os.File, io.Reader], listOfFilePointers)

This appears alone because reflect is a heavy import

func Range

func Range[K comparable, V any, R Rangeable[K, V]](
	f func(K, V) error,
	r R,
) (K, error)

Range calls some function f(k, v) => err over any Rangeable of (K, V)s. If the return value of f is not nil, the iteration stops immediately, and returns (k, err) for the given k. Otherwise, returns (zero, nil).

Caution: invalid key types will panic at runtime. The key type must be int for any type other than a map. See Rangeable for details. In a channel, the key is always zero.

func WithCloser deprecated

func WithCloser[T io.Closer](opener func() (T, error), do func(v T) error) error

WithCloser ...

Deprecated: don't use

Types

type Rangeable

type Rangeable[K comparable, V any] interface {
	~string | ~map[K]V | ~[]V | chan V
}

Rangeable defines any type of value x where it is possible to range over using "for k, v := range x" or "v := range x" (in the case of a channel, only "v := range x" is permitted). For every Rangeable other than a map, K must always be int.

Jump to

Keyboard shortcuts

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