NilToDefault coalesces a nil value to the provided default value.
(s *T, def T)
| 28 | |
| 29 | // NilToDefault coalesces a nil value to the provided default value. |
| 30 | func NilToDefault[T any](s *T, def T) T { |
| 31 | if s == nil { |
| 32 | return def |
| 33 | } |
| 34 | return *s |
| 35 | } |
| 36 | |
| 37 | // NilOrZero returns true if v is nil or 0. |
| 38 | func NilOrZero[T number](v *T) bool { |
no outgoing calls