util

package
v0.0.0-...-8945333 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllUntilError1

func AllUntilError1[F ~func(A) error, A any](fs ...F) F

AllUntilError1 returns a new function that calls all fs in order until one returns an error, and returns it, or if none fail, returns nil.

If fs... is empty, a function that does nothing and returns nil is returned.

func AllUntilError2

func AllUntilError2[F ~func(A1, A2) error, A1, A2 any](fs ...F) F

AllUntilError2 returns a new function that calls all fs in order until one returns an error, and returns it, or if none fail, returns nil.

If fs... is empty, a function that does nothing and returns nil is returned.

func Apply

func Apply[T any](t T, f func(T)) T

Apply calls f with t, and then returns t.

func Chain1

func Chain1[F ~func(A) A, A any](fs ...F) F

Chain1 returns a new function that when called, returns the result of calling fs... in the provided order.

If fs... is empty, then the identity function for F is returned, where the return value is equal to the argument.

func ChainReverse1

func ChainReverse1[F ~func(A) A, A any](fs ...F) F

ChainReverse1 returns a new function that when called, returns the result of calling fs... in the opposite of the provided order.

If fs... is empty, then the identity function for F is returned, where the return value is equal to the argument.

func FoldBool

func FoldBool[T any](success bool, onSuccess, onFailure T) T

func FoldBoolFunc

func FoldBoolFunc[T any](success bool, onSuccess, onFailure func() T) T

func IsZero

func IsZero[T comparable](v T) bool

func MapMap

func MapMap[M ~map[K]V, K comparable, V any, OK comparable, OV any](m M, mapper func(K, V) (OK, OV)) map[OK]OV

func MapSlice

func MapSlice[S ~[]T, T any, O any](slice S, mapper func(T) O) []O

func MapSliceIndexed

func MapSliceIndexed[S ~[]T, T any, O any](slice S, mapper func(int, T) O) []O

func Must

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

func SliceDiff

func SliceDiff[S ~[]T, T comparable](before, after S) (additions, deletions S)

SliceDiff does the same thing as SliceDiffBy, but is a convenience for values that are directly comparable (or otherwise don't need custom comparison logic).

func SliceDiffBy

func SliceDiffBy[S ~[]T, T any](before, after S, equal func(T, T) bool) (additions, deletions S)

SliceDiffBy returns two slices representing the additions and deletions done on before to get after. In other words, by adding everything in additions to before, and removing everything in deletions from before, the result would be equal to after.

Both before and after should be sorted in the same manner (method and order).

func SliceDistinct

func SliceDistinct[S ~[]T, T cmp.Ordered](slice S) S

SliceDistinct is the same as SliceDistinctBy, but is more convenient for types that already satisfy cmp.Ordered.

func SliceDistinctBy

func SliceDistinctBy[S ~[]T, T any](slice S, cmp func(T, T) int) S

SliceDistinctBy removes duplicate elements from slice as identified by cmp, and returns the resulting modified slice.

Note that in addition to contents, the order of elements in the resulting slice is note stable.

func Zero

func Zero[T any]() (zero T)

Types

This section is empty.

Jump to

Keyboard shortcuts

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