Documentation
¶
Index ¶
- func CopyBytes(b []byte) []byte
- func CopyString(s string) string
- func Default[T comparable](values ...T) T
- func Pointer[T any](value T) *T
- func Tap[T any](value T, callbacks ...func(T)) T
- func Transform[T, R any](value T, callback func(T) R) R
- func UnsafeBytes(s string) []byte
- func UnsafeString(b []byte) string
- func With[T any](value T, callbacks ...func(T) T) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyString ¶ added in v1.0.8
CopyString copies a string to make it immutable
func Default ¶
func Default[T comparable](values ...T) T
Default returns the first non-zero value. If all values are zero, return the zero value.
Default("", "foo") // "foo" Default("bar", "foo") // "bar" Default("", "", "foo") // "foo"
func Pointer ¶
func Pointer[T any](value T) *T
Pointer returns a pointer to the value.
Pointer("foo") // *string("foo") Pointer(1) // *int(1)
func Tap ¶
func Tap[T any](value T, callbacks ...func(T)) T
Tap calls the given callback with the given value then returns the value.
Tap("foo", func(s string) { fmt.Println(s) // "foo" and os.Stdout will print "foo" }, func(s string) { // more callbacks }...)
func Transform ¶
func Transform[T, R any](value T, callback func(T) R) R
Transform calls the given callback with the given value then return the result.
Transform(1, strconv.Itoa) // "1" Transform("foo", func(s string) *foo { return &foo{Name: s} }) // &foo{Name: "foo"}
func UnsafeBytes ¶ added in v1.0.8
UnsafeBytes returns a byte pointer without allocation.
func UnsafeString ¶ added in v1.0.8
UnsafeString returns a string pointer without allocation
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.