pointer

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: AGPL-3.0 Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pointer provides generic utility functions for creating pointers to values and dereferencing pointer values and slices.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dereference

func Dereference[T any](x *T) T

Dereference returns the value of a pointer.

Example
package main

import (
	"fmt"

	"github.com/primandproper/platform-go/pointer"
)

func main() {
	s := "world"
	val := pointer.Dereference(&s)
	fmt.Println(val)
}
Output:
world
Example (Nil)
package main

import (
	"fmt"

	"github.com/primandproper/platform-go/pointer"
)

func main() {
	val := pointer.Dereference[string](nil)
	fmt.Println(val)
}

func DereferenceSlice

func DereferenceSlice[T any](x []*T) []T

DereferenceSlice returns the value of a pointer for every element in a slice.

Example
package main

import (
	"fmt"

	"github.com/primandproper/platform-go/pointer"
)

func main() {
	a, b, c := 10, 20, 30
	vals := pointer.DereferenceSlice([]*int{&a, &b, &c})
	fmt.Println(vals)
}
Output:
[10 20 30]

func To

func To[T any](x T) *T

To returns a pointer to a value.

Example
package main

import (
	"fmt"

	"github.com/primandproper/platform-go/pointer"
)

func main() {
	p := pointer.To("hello")
	fmt.Println(*p)
}
Output:
hello

func ToSlice

func ToSlice[T any](x []T) []*T

ToSlice returns the value of a pointer for every element in a slice.

Example
package main

import (
	"fmt"

	"github.com/primandproper/platform-go/pointer"
)

func main() {
	vals := []int{1, 2, 3}
	ptrs := pointer.ToSlice(vals)
	fmt.Println(*ptrs[0], *ptrs[1], *ptrs[2])
}
Output:
1 2 3

Types

This section is empty.

Jump to

Keyboard shortcuts

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