Documentation ¶
Overview ¶
optional.go is a simple wrapper around a value and a presence flag
Index ¶
- type Optional
- func (optional Optional[T]) AssertNone()
- func (optional Optional[T]) AssertSome()
- func (optional Optional[T]) GetElseAlt(alternative T) T
- func (optional Optional[T]) GetElseDefault() T
- func (optional Optional[T]) GetElseFrom(alternative func() T) Optional[T]
- func (optional Optional[T]) GetTransformedElseNone(transformer func(T) T) Optional[T]
- func (optional Optional[T]) IsNone() bool
- func (optional Optional[T]) IsSome() bool
- func (optional Optional[T]) MarshalCSV() (string, error)
- func (optional Optional[T]) MarshalJSON() ([]byte, error)
- func (optional *Optional[T]) MarshalText() (text []byte, err error)
- func (optional Optional[T]) Match(someHandler func(T), noneHandler func(T))
- func (optional Optional[T]) MustGet() T
- func (optional *Optional[T]) Scan(value any) error
- func (optional *Optional[T]) Set(val T)
- func (optional Optional[T]) String() string
- func (optional Optional[T]) TryGetElseFrom(alternative func() (T, error)) result.Result[T]
- func (optional *Optional[T]) UnmarshalCSV(val string) error
- func (optional *Optional[T]) UnmarshalJSON(input []byte) error
- func (optional *Optional[T]) UnmarshalText(text []byte) error
- func (optional *Optional[T]) Unset() T
- func (optional Optional[T]) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Optional ¶
type Optional[T any] struct { // contains filtered or unexported fields }
Optional holds a Wrappe and a flag indicating the existence or abscence of the Wrapee.
func None ¶
None creates an optional holding the specified wrappee and sets the hasValue flag to false.
func Some ¶
Some creates an optional holding the specified wrappee and sets the hasValue flag to true.
func (Optional[T]) AssertNone ¶
func (optional Optional[T]) AssertNone()
func (Optional[T]) AssertSome ¶
func (optional Optional[T]) AssertSome()
func (Optional[T]) GetElseAlt ¶
func (optional Optional[T]) GetElseAlt(alternative T) T
GetElseAlt returns the Wrapee if the hasValue flag is true, otherwise alternative is returned.
func (Optional[T]) GetElseDefault ¶
func (optional Optional[T]) GetElseDefault() T
GetOrDefualt returns the Wrapee if the hasValue flag is true, otherwise T's default value is returned.
func (Optional[T]) GetElseFrom ¶
GetElseFrom returns the Wrapee if the hasValue flag is true, otherwise the result of alternative() is returned.
func (Optional[T]) GetTransformedElseNone ¶
GetTransformedOrEmpty returns transformer(wrappee) if hasValue == true, otherwise returns self.
func (Optional[T]) MarshalCSV ¶
MarshalCSV implements the gocarina/gocsv.TypeMarshaller interface.
func (Optional[T]) MarshalJSON ¶
func (*Optional[T]) MarshalText ¶
MarshalText implements the encoding.TextMarshaller interface.
func (Optional[T]) Match ¶
func (optional Optional[T]) Match(someHandler func(T), noneHandler func(T))
Match executes someHandler if hasValue is true and noneHandler otherwise.
func (*Optional[T]) Set ¶
func (optional *Optional[T]) Set(val T)
Set sets a wrappee to val value and the hasValue flag to true.
func (Optional[T]) TryGetElseFrom ¶
func (*Optional[T]) UnmarshalCSV ¶
UnmarshalCSV implements the gocarina/gocsv.TypeUnmarshaller interface.
func (*Optional[T]) UnmarshalJSON ¶
func (*Optional[T]) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaller interface.