Skip to content
On this page

Index

func PointerSlice

go
func PointerSlice[T any](slice []any) []*T

PointerSlice is a function to cast a slice of any values ([]any) to a slice of the given type pointers.

Usage:

// Let's assume we have []any{1, 2, nil} in "values" variable.
cast.PointerSlice(int)([]any{1, 2, nil}) // []*int{1, 2, nil}

func Slice

go
func Slice[T any](slice []any) []T

Slice is a function to cast a slice of any values ([]any) to a slice of the given type.

Usage:

// Let's assume we have []any{1, 2, 3} in "values" variable.
cast.Slice[int](values) // []int{1, 2, 3}

Generated by gomarkdoc