Created
August 17, 2021 11:46
-
-
Save ninedraft/9ab089624cca4a4b1f65cec1d3fdd1e3 to your computer and use it in GitHub Desktop.
Generic go trash utilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package value | |
func If[E any](ok bool, then, or E) E { | |
if ok { | |
return then | |
} | |
return or | |
} | |
func Ptr[E any](v E) *E { | |
return &v | |
} | |
func Deref[E any](v *E, or E) E { | |
if v == nil { | |
return or | |
} | |
return *v | |
} | |
func Empty[E any]() E { | |
var v E | |
return v | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment