Documentation ¶
Index ¶
- type Type
- func (o Type[T]) Filter(f func(T) bool) Type[T]
- func (o Type[T]) Get() T
- func (o Type[T]) IfPresent(f func(T))
- func (o Type[T]) IsEmpty() bool
- func (o Type[T]) IsPresent() bool
- func (o Type[T]) MarshalJSON() ([]byte, error)
- func (o Type[T]) OrElse(v T) T
- func (o Type[T]) OrElseGet(f func() T) T
- func (o *Type[T]) Scan(value interface{}) error
- func (o *Type[T]) UnmarshalJSON(data []byte) error
- func (o Type[T]) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Type ¶
type Type[T interface{}] struct {
// contains filtered or unexported fields
}
The Optional Type.
Example: var foo optl.Type[string]
func Empty ¶
func Empty[T interface{}]() Type[T]
Constructor of an empty optional.
Sample 1: foo := optl.Empty[string]()
Sample 2: bar := optl.Empty[MyStruct]()
func Of ¶
func Of[T interface{}](v T) Type[T]
Constructor of an optional with value.
Example 1: foo := optl.Of("Hello optional")
Example 2: bar := optl.Of(2.3)
Example 3: baz := optl.Of[int64](3)
Example 4: quux := optl.Of(MyStruct{...})
func OfNillable ¶
func OfNillable[T interface{}](v *T) Type[T]
Constructor of an optional with nillable value (pointer to value).
var bar * string
...
Example: foo := optl.OfNillable(bar)
func (Type[T]) Filter ¶
If the value is present executes the lambda function passed as parameter with the current value. If this function return false return a empty optional else return the current optional.
func (Type[T]) Get ¶
func (o Type[T]) Get() T
Return the value of the optional, if it is not present throw a panic error.
func (Type[T]) IfPresent ¶
func (o Type[T]) IfPresent(f func(T))
If the value is present executes the lambda function passed as parameter with the current value.
func (Type[T]) OrElse ¶
func (o Type[T]) OrElse(v T) T
If value is present return the current value, else return the value passed as parameter.
func (Type[T]) OrElseGet ¶
func (o Type[T]) OrElseGet(f func() T) T
If value is present return the current value, else return the value returned by lambda function passed as parameter.
func (*Type[T]) UnmarshalJSON ¶
JSON unmarshaller