convert

package
v1.14.8 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 With

func With[T any](value T, callbacks ...func(T) T) T

With calls the given callbacks with the given value then return the value.

With("foo", func(s string) string {
	return s + "bar"
}, func(s string) string {
	return s + "baz"
}) // "foobarbaz"

Types

This section is empty.

Jump to

Keyboard shortcuts

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