blob: 9754e2d1d598d90500bf38d55cbe0a32af12d7a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
/*******************************************************************************
* Copyright 2025 Stefan Majewsky <majewsky@gmx.net>
* SPDX-License-Identifier: Apache-2.0
* Refer to the file "LICENSE" for details.
*******************************************************************************/
// Package options provides additional functions for type option.Option
// that cannot be expressed as methods on the Option type itself.
package options
import . "github.com/majewsky/gg/option"
// NOTE: Keep functions sorted by name.
// FromPointer converts a *T into an Option[T].
func FromPointer[T any](value *T) Option[T] {
if value == nil {
return None[T]()
} else {
return Some(*value)
}
}
// IsNoneOrZero returns whether the Option is either empty, or contains a zero value.
func IsNoneOrZero[T comparable](o Option[T]) bool {
return o.IsNoneOr(func(value T) bool {
var zero T
return zero == value
})
}
|