Help us shape the future of Go! Take the 2026 Go Developer Survey

pval

package module
v0.0.0-...-3fc3486 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2018 License: CC0-1.0 Imports: 0 Imported by: 0

README

pval = Pointer to Value

Since Go does not allow addressing a constant, and literal primitives are considered constants in this regard, it makes some code long-winded and noisy. I use this a lot in unit tests to keep them small and on-topic, but it's generally useful for areas of code where terseness is preferred over idiomatic grammar. I was annoyed, so I created this package.

Replace unnecessarily long code like the following:

var result *string

// ... do stuff

foo := "bar"
result = &foo

With this:

var result *string

// ... do stuff

result := pval.String("bar")

It's even worse if you happen to need a slice of pointers. Replace this eyesore:

var result []*string

// ... do stuff

foo1 := "bar1"
foo2 := "bar2"
foo3 := "bar3"
foo4 := "bar4"
result = append(result, &foo1, &foo2, &foo3, &foo4)

With this (the plural version):

var result []*string

// ... do stuff

result := pval.Strings("bar1", "bar2", "bar3", "bar4")

License

Creative Commons CC0 alt text

To the extent possible under law, Gerry Hernandez has waived all copyright and related or neighboring rights to pval.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(val bool) *bool

func Bools

func Bools(vals ...bool) []*bool

func Byte

func Byte(val byte) *byte

func Bytes

func Bytes(vals ...byte) []*byte

func Complex64

func Complex64(val complex64) *complex64

func Complex64s

func Complex64s(vals ...complex64) []*complex64

func Complex128

func Complex128(val complex128) *complex128

func Complex128s

func Complex128s(vals ...complex128) []*complex128

func Float32

func Float32(val float32) *float32

func Float32s

func Float32s(vals ...float32) []*float32

func Float64

func Float64(val float64) *float64

func Float64s

func Float64s(vals ...float64) []*float64

func Int

func Int(val int) *int

func Int8

func Int8(val int8) *int8

func Int8s

func Int8s(vals ...int8) []*int8

func Int16

func Int16(val int16) *int16

func Int16s

func Int16s(vals ...int16) []*int16

func Int32

func Int32(val int32) *int32

func Int32s

func Int32s(vals ...int32) []*int32

func Int64

func Int64(val int64) *int64

func Int64s

func Int64s(vals ...int64) []*int64

func Ints

func Ints(vals ...int) []*int

func Rune

func Rune(val rune) *rune

func Runes

func Runes(vals ...rune) []*rune

func String

func String(val string) *string

func Strings

func Strings(vals ...string) []*string

func Uint8

func Uint8(val uint8) *uint8

func Uint8s

func Uint8s(vals ...uint8) []*uint8

func Uint16

func Uint16(val uint16) *uint16

func Uint16s

func Uint16s(vals ...uint16) []*uint16

func Uint32

func Uint32(val uint32) *uint32

func Uint32s

func Uint32s(vals ...uint32) []*uint32

func Uint64

func Uint64(val uint64) *uint64

func Uint64s

func Uint64s(vals ...uint64) []*uint64

func Uintptr

func Uintptr(val uintptr) *uintptr

func Uintptrs

func Uintptrs(vals ...uintptr) []*uintptr

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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