Skip to content

Commit

Permalink
Add generic To and Get
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Aug 21, 2021
1 parent 4032d40 commit 2eade2a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions generic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package pointer

func To[T any](t T) *T {
return &t
}

func Get[T any](t *T) T {
if t == nil {
var zero T
return zero
}
return *t
}

// No `func ToOrNil[T any](t T) *T` due to time.Time.Equal

0 comments on commit 2eade2a

Please sign in to comment.