diff --git a/to.go b/to.go index 855e0d2..e358bce 100644 --- a/to.go +++ b/to.go @@ -17,6 +17,16 @@ func Deref[T any](s []*T) []T { return out } +// Ref returns a slice containing pointers to all values of s. +// The order in s is preserved. +func Ref[T any](s []T) []*T { + out := make([]*T, 0, len(s)) + Each(s, func(v T) { + out = append(out, &v) + }) + return out +} + // ToList returns a list.List containing all values of s func ToList[T any](s []T) *list.List { l := list.New()