util

package
v0.0.0-...-cbbd1a2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstOf

func ConstOf[S any, T any](t T) func(S) T

func Contextualize

func Contextualize[CC, ERC, IRC, T any](
	contextualizer Contextualizer[CC, ERC, IRC, T],
	configCtx CC,
	f func(externalRuntimeCtx ERC, internalRuntimeCtx IRC) (T, error),
) func(externalRuntimeCtx ERC) (T, error)

Contextualize returns a function that is the partial application of f within the execution context provided by contextualizer.

func Contextualize1

func Contextualize1[CC, ERC, IRC, S1, T any](
	contextualizer Contextualizer[CC, ERC, IRC, T],
	configCtx CC,
	f func(externalRuntimeCtx ERC, internalRuntimeCtx IRC, s1 S1) (T, error),
) func(externalRuntimeCtx ERC, s1 S1) (T, error)

Contextualize1 returns a function that is the partial application of f within the execution context provided by contextualizer.

func Contextualize1V

func Contextualize1V[CC, ERC, IRC, S1 any](
	contextualizer Contextualizer[CC, ERC, IRC, types.Unit],
	configCtx CC,
	f func(externalRuntimeCtx ERC, internalRuntimeCtx IRC, s1 S1),
) func(externalRuntimeCtx ERC, s1 S1)

Contextualize1V returns a function that is the partial application of f within the execution context provided by contextualizer.

func Contextualize2

func Contextualize2[CC, ERC, IRC, S1, S2, T any](
	contextualizer Contextualizer[CC, ERC, IRC, T],
	configCtx CC,
	f func(externalRuntimeCtx ERC, internalRuntimeCtx IRC, s1 S1, s2 S2) (T, error),
) func(externalRuntimeCtx ERC, s1 S1, s2 S2) (T, error)

Contextualize2 returns a function that is the partial application of f within the execution context provided by contextualizer.

func Duration

func Duration(msg string, start time.Time)

func Ignore

func Ignore(v ...any)

Ignore is used to remove "unused variable" compilation wrrors without having to remove the variable(s).

func LiftToNullary

func LiftToNullary[S, T any](f func(S) T) func(func() S) func() T

func MapToSlice

func MapToSlice[K comparable, V any](m map[K]V) []V

func PointerOf

func PointerOf[T any](v T) *T

func SafeCast

func SafeCast[T any](x any) T

Safely casts x to type T, returning the zero value of T if x is not of type T.

func SliceContains

func SliceContains[T comparable](slice []T, value T) bool

func SliceFilter

func SliceFilter[S any](xs []S, f func(S) bool) []S

func SliceMap

func SliceMap[S, T any](xs []S, f func(S) T) []T

func SliceMapWithIndex

func SliceMapWithIndex[S, T any](xs []S, f func(int, S) T) []T

func SliceReverse

func SliceReverse[S any](xs []S) []S

func SliceToBoolSet

func SliceToBoolSet[T comparable](s []T) map[T]bool

SliceToBoolSet returns a set containing the values in the receiver.

func SliceToUnitSet

func SliceToUnitSet[T comparable](s []T) map[T]types.Unit

SliceToUnitSet returns a set containing the values in the receiver.

func SliceWindow

func SliceWindow(slice []any, limit, offset int) []any

func Slug

func Slug(title string) string

func Sort

func Sort(slice []any, less func(i, j int) bool)

func ThunkOf

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

func TimeLeft

func TimeLeft(deadline time.Time) time.Duration

TimeLeft converts a deadline to a timeout by subtracting the current time from the deadline. If the difference is negative, it returns zero.

func Todo

func Todo[T any]() T

func Trace

func Trace(name string) func()

Trace provides entry and exit tracing for functions, by using it in a defer statement as `defer Trace(name)()`

func Track

func Track(msg string) (string, time.Time)

Types

type Contextualizer

type Contextualizer[CC, ERC, IRC, T any] func(
	configCtx CC,
	externalRuntimeCtx ERC,
	block func(externalRuntimeCtx ERC, internalRuntimeCtx IRC) (T, error),
) (T, error)

Contextualizer represents a higher-order function that executes another function within a context. An example is a function that executes a target function while delimiting the target function within a transaction.

- configCtx represents configuration data that is passed to the higher-orfer function. For example, a database object.

- externalRuntimeCtx represents a runtime context input for use by both the Contextualizer and the target function. For example, context.Context.

- internalRuntimeCtx is a runtime argument produced by the Contextualizer and passed to the target function. For example, a transaction object.

type Uuid

type Uuid string

func NewUuid

func NewUuid() Uuid

Jump to

Keyboard shortcuts

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