github
69 of 69 new or added lines in 4 files covered. (100.0%)
6257 of 8289 relevant lines covered (75.49%)
580.56 hits per line
1 |
package graphql
|
|
2 |
|
|
3 |
// Omittable represents a value that can be omitted.
|
|
4 |
type Omittable[T any] struct { |
|
5 |
value T |
|
6 |
set bool
|
|
7 |
} |
|
8 |
|
|
|
func OmittableOf[T any](value T) Omittable[T] {
|
36✔ |
|
return Omittable[T]{
|
36✔ |
|
value: value, |
36✔ |
|
set: true,
|
36✔ |
|
} |
36✔ |
|
} |
36✔ |
15 |
|
|
|
func (o Omittable[T]) Value() T {
|
× |
|
if !o.set {
|
× |
|
var zero T
|
× |
|
return zero
|
× |
|
} |
× |
|
return o.value
|
× |
22 |
} |
|
23 |
|
|
|
func (o Omittable[T]) ValueOK() (T, bool) { |
52✔ |
|
if !o.set {
|
68✔ |
|
var zero T
|
16✔ |
|
return zero, false |
16✔ |
|
} |
16✔ |
|
return o.value, true |
36✔ |
30 |
} |
|
31 |
|
|
|
func (o Omittable[T]) IsSet() bool { |
× |
|
return o.set
|
× |
|
} |
× |