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

ptr

package
v0.11.11 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 0 Imported by: 32

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Of added in v0.4.0

func Of[T any](v T) *T

Of returns pointer of a given generic type

Example:

var v int
var p = ptr.Of(v)

func Safe

func Safe[T any](v *T) T

Safe dereferences safely a pointer - if the pointer is nil => returns the zero value of the type of the pointer if nil - if the pointer is not nil => returns the dereferenced pointer

Example:

var v *int
var x = ptr.Safe(v)

func When added in v0.4.0

func When[T any](v T, condition bool) *T

When returns pointer of a given generic type - if the condition is false => returns nil - if the condition is true => returns pointer of the value

Example:

var v bool
var p = ptr.When(v, v != false)

Types

This section is empty.

Jump to

Keyboard shortcuts

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