NilToEmpty coalesces a nil value to the empty value.
(s *T)
| 19 | |
| 20 | // NilToEmpty coalesces a nil value to the empty value. |
| 21 | func NilToEmpty[T any](s *T) T { |
| 22 | var def T |
| 23 | if s == nil { |
| 24 | return def |
| 25 | } |
| 26 | return *s |
| 27 | } |
| 28 | |
| 29 | // NilToDefault coalesces a nil value to the provided default value. |
| 30 | func NilToDefault[T any](s *T, def T) T { |
no outgoing calls