ptr

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: MIT Imports: 0 Imported by: 17

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