Documentation ¶
Index ¶
- func CompareOptional[E constraints.Ordered](a, b Optional[E]) int
- func Pointer[T any](v T) *T
- func PointerMap[M ~map[K]V, N map[K]*V, K comparable, V any](src M) N
- func PointerSlice[S ~[]E, V []*E, E any](src S) V
- func Value[T any](v *T) T
- func ValueMap[M ~map[K]*V, N map[K]V, K comparable, V any](src M) N
- func ValueSlice[S ~[]*E, V []E, E any](src S) V
- type Optional
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareOptional ¶ added in v1.2.77
func CompareOptional[E constraints.Ordered](a, b Optional[E]) int
func PointerMap ¶
func PointerMap[M ~map[K]V, N map[K]*V, K comparable, V any](src M) N
PointerMap converts a map of values into a map of pointers
func PointerSlice ¶
func PointerSlice[S ~[]E, V []*E, E any](src S) V
PointerSlice converts a slice of values into a slice of pointers
func Value ¶
func Value[T any](v *T) T
Value returns the value of the pointer passed in or "" if the pointer is nil.
func ValueMap ¶
func ValueMap[M ~map[K]*V, N map[K]V, K comparable, V any](src M) N
ValueMap converts a map of string pointers into a string map of values
func ValueSlice ¶
func ValueSlice[S ~[]*E, V []E, E any](src S) V
ValueSlice converts a slice of pointers into a slice of values
Types ¶
type Optional ¶ added in v1.2.77
Optional represents a Value that may be null.
func (Optional[E]) Format ¶ added in v1.2.77
Example ¶
package main import ( "fmt" "github.com/searKing/golang/go/exp/types" ) func main() { fmt.Printf("'%+v'\n", types.Optional[string]{}) fmt.Printf("'%v'\n", types.Optional[string]{}) fmt.Printf("'%s'\n", types.Optional[string]{}) fmt.Printf("'%+v'\n", types.Optional[int]{}) fmt.Printf("'%v'\n", types.Optional[int]{}) fmt.Printf("'%s'\n", types.Optional[int]{}) fmt.Printf("'%+v'\n", types.Optional[*int]{}) fmt.Printf("'%v'\n", types.Optional[*int]{}) fmt.Printf("'%s'\n", types.Optional[*int]{}) fmt.Printf("'%+v'\n", types.Opt("")) fmt.Printf("'%v'\n", types.Opt("")) fmt.Printf("'%s'\n", types.Opt("")) fmt.Printf("'%+v'\n", types.Opt(0)) fmt.Printf("'%v'\n", types.Opt(0)) fmt.Printf("'%s'\n", types.Opt(0)) fmt.Printf("'%+v'\n", types.Opt[*int](nil)) fmt.Printf("'%v'\n", types.Opt[*int](nil)) fmt.Printf("'%s'\n", types.Opt[*int](nil)) fmt.Printf("'%+v'\n", types.Opt("hello world")) fmt.Printf("'%v'\n", types.Opt("hello world")) fmt.Printf("'%s'\n", types.Opt("hello world")) fmt.Printf("'%+v'\n", types.Opt(0xFF)) fmt.Printf("'%v'\n", types.Opt(0xFF)) fmt.Printf("'%s'\n", types.Opt(0xFF)) var p int fmt.Printf("'%s'\n", fmt.Sprintf("%+v", types.Opt(&p))[:2]) fmt.Printf("'%s'\n", fmt.Sprintf("%v", types.Opt(&p))[:2]) fmt.Printf("'%s'\n", fmt.Sprintf("%s", types.Opt(&p))[:11]) }
Output: 'null string: ' 'null' 'null' 'null int: 0' 'null' 'null' 'null *int: <nil>' 'null' 'null' '' '' '' '0' '0' '%!s(int=0)' '<nil>' '<nil>' '%!s(*int=<nil>)' 'hello world' 'hello world' 'hello world' '255' '255' '%!s(int=255)' '0x' '0x' '%!s(*int=0x'
func (Optional[E]) String ¶ added in v1.2.77
Example ¶
package main import ( "fmt" "github.com/searKing/golang/go/exp/types" ) func main() { fmt.Printf("%s\n", types.Optional[string]{}.String()) fmt.Printf("%s\n", types.Optional[int]{}.String()) fmt.Printf("%s\n", types.Optional[*int]{}.String()) fmt.Printf("%s\n", types.Opt("").String()) fmt.Printf("%s\n", types.Opt(0).String()) fmt.Printf("%s\n", types.Opt[*int](nil).String()) fmt.Printf("%s\n", types.Opt("hello world").String()) fmt.Printf("%s\n", types.Opt(0xFF).String()) var p int fmt.Printf("%s\n", types.Opt(&p).String()[:2]) }
Output: null null null 0 <nil> hello world 255 0x
Click to show internal directories.
Click to hide internal directories.