tricks

package module
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: GPL-3.0 Imports: 1 Imported by: 5

README

Tricks Coverage Badge

Frequent magics every developer may need

Usage

go get github.com/janstoon/toolbox/tricks

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateEntry = errors.New("duplicate entry")

Functions

func ApplyOptions

func ApplyOptions[S any](s *S, oo ...Option[S]) *S

func Coalesce

func Coalesce[T comparable](tt ...T) T

Coalesce returns left-most non-zero value

func Filter

func Filter[T any](tt []T, match func(src T) bool) []T

func Find

func Find[T any](tt []T, match func(src T) bool) *T

func FindIndex

func FindIndex[T any](tt []T, match func(src T) bool) int

func Flat added in v0.6.3

func Flat[T any](slices ...[]T) []T

func FromAny added in v0.8.1

func FromAny[T any](src any) T

func IndexOf

func IndexOf[T comparable](expected T, tt []T) int

func InsertIfNotExist

func InsertIfNotExist[K comparable, V any](hm map[K]V, key K, value V)

func Map

func Map[S, D any](ss []S, transformer Transformer[S, D]) []D

func MatchEqual

func MatchEqual[T comparable](expected T) func(actual T) bool

func PtrPtr

func PtrPtr[S, D any](src *S, transformer Transformer[S, D]) *D

PtrPtr transforms pointer of type S to pointer of type D. If src is nil it returns nil

func PtrVal

func PtrVal[T any](src *T) T

PtrVal dereferences a pointer of type T. If it's nil it returns the zero value of T

func Reduce

func Reduce[T, R any](tt []T, reducer func(r R, t T) R) R

func StringToRunes

func StringToRunes(src string) []rune

func ToAny added in v0.8.1

func ToAny[T any](src T) any

func ValPtr

func ValPtr[T any](src T) *T

ValPtr converts a value of type T to its pointer

Types

type InPlaceOption

type InPlaceOption[S any] func(s *S)

func (InPlaceOption[S]) Apply

func (o InPlaceOption[S]) Apply(s *S) *S

type Option

type Option[S any] interface {
	Apply(s *S) *S
}

type OutOfPlaceOption

type OutOfPlaceOption[S any] func(s S) S

func (OutOfPlaceOption[S]) Apply

func (o OutOfPlaceOption[S]) Apply(s *S) *S

type Transformer

type Transformer[S, D any] func(src S) D

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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