pointer

package
v1.85.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package pointer is an attempt to provide functions to convert data to pointers using generics. inspired by https://pkg.go.dev/github.com/aws/smithy-go/ptr This is intended to replace the following patterns that we've seen across our codebase: - myVar := "value"; return &myVar - ptr.{SomeType}("value") Also Enables the possibility to use: var res *myStructType = ToPtr(myStructType{}) and any derivate with map / slice

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToMapPtr

func ToMapPtr[K comparable, T any](objectMap map[K]T) map[K]*T

ToMapPtr returns a map of pointers of type *T pointing to each element of {objectMap}

func ToMapValue

func ToMapValue[K comparable, T any](ptrs map[K]*T) map[K]T

ToSliceValue returns a map of values of type T pointed by each pointers in {ptrs} if a pointer in {ptrs} is nil the value at the corresponding key will be the 0 of T

func ToPtr

func ToPtr[T any](object T) *T

ToPtr returns a pointer to {object} of type *T

func ToSlicePtr

func ToSlicePtr[T any](objects []T) []*T

ToSlicePtr returns a slice of pointers of type *T pointing to each element of {objects}

func ToSliceValue

func ToSliceValue[T any](ptrs []*T) []T

ToSliceValue returns a slice of values of type T pointed by each pointers in {ptrs} if a pointer in {ptrs} is nil the value at the corresponding index will be the 0 of T

func ToValue

func ToValue[T any](ptr *T) (res T)

ToValue returns the value of type T pointed by {ptr} if {ptr} is nil, return 0 value of T

Types

This section is empty.

Jump to

Keyboard shortcuts

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