push
github
3 of 13 new or added lines in 1 file covered. (23.08%)
2271 of 3103 relevant lines covered (73.19%)
4.14 hits per line
1 |
package optional
|
|
2 |
|
|
3 |
var empty = &optional{v: nil} |
|
4 |
|
|
5 |
// optional struct
|
|
6 |
type optional struct { |
|
7 |
v interface{}
|
|
8 |
} |
|
9 |
|
|
|
func Of(data interface{}) *optional { |
5✔ |
|
return &optional{v: data}
|
5✔ |
|
} |
5✔ |
13 |
|
|
NEW
|
func OfNillable(data interface{}) *optional { |
× |
NEW
|
if data == nil { |
× |
NEW
|
return empty
|
× |
NEW
|
} |
× |
18 |
|
|
NEW
|
return &optional{v: data}
|
× |
20 |
} |
|
21 |
|
|
NEW
|
func (o *optional) Map(fn func(v interface{}) interface{}) *optional { |
× |
NEW
|
if o.v == nil { |
× |
NEW
|
return empty
|
× |
NEW
|
} |
× |
26 |
|
|
NEW
|
return OfNillable(fn(o.v))
|
× |
28 |
} |