convert

package
v1.15.12 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindingToFacade added in v1.15.12

func BindingToFacade(binding string) string

func CopyBytes added in v1.15.12

func CopyBytes(b []byte) []byte

CopyBytes copies a slice to make it immutable

func CopyString added in v1.15.12

func CopyString(s string) string

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 FacadeToBinding added in v1.15.12

func FacadeToBinding(facade string) string

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 ToAnySlice added in v1.15.12

func ToAnySlice[T any](s ...T) []any

ToAnySlice converts a slice of any type T to a slice of type []any. It supports both variadic arguments and slice arguments.

ToAnySlice("foo", "bar") // []any{"foo", "bar"}
ToAnySlice([]int{1, 2, 3}) // []any{1, 2, 3}

func ToSlice added in v1.15.12

func ToSlice[T int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64](i any) []T

func ToSliceE added in v1.15.12

func ToSliceE[T int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64](i any) ([]T, error)

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.15.12

func UnsafeBytes(s string) []byte

UnsafeBytes returns a byte pointer without allocation.

func UnsafeString added in v1.15.12

func UnsafeString(b []byte) string

UnsafeString returns a string pointer without allocation

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