Documentation ¶
Overview ¶
Package use provides conditional expression builders
Index ¶
- type When
- func (w When[T]) Else(fals T) T
- func (w When[T]) ElseErr(err error) (T, error)
- func (w When[T]) ElseGet(fals func() T) T
- func (w When[T]) ElseGetErr(fals func() (T, error)) (T, error)
- func (w When[T]) ElseZero() (out T)
- func (w When[T]) Eval() (out T, ok bool)
- func (w When[T]) If(condition bool, tru T) When[T]
- func (w When[T]) IfGet(condition bool, tru func() T) When[T]
- func (w When[T]) IfGetErr(condition bool, tru func() (T, error)) WhenErr[T]
- func (w When[T]) Or(other When[T]) When[T]
- func (w When[T]) Other(condition func() bool, tru func() T) When[T]
- func (w When[T]) OtherErr(condition func() bool, tru func() (T, error)) WhenErr[T]
- type WhenErr
- func (w WhenErr[T]) Else(fals T) (T, error)
- func (w WhenErr[T]) ElseErr(err error) (T, error)
- func (w WhenErr[T]) ElseGet(fals func() T) (T, error)
- func (w WhenErr[T]) ElseGetErr(fals func() (T, error)) (T, error)
- func (w WhenErr[T]) ElseZero() (out T, err error)
- func (w WhenErr[T]) Eval() (out T, ok bool, err error)
- func (w WhenErr[T]) If(condition bool, tru T) WhenErr[T]
- func (w WhenErr[T]) IfGet(condition bool, tru func() T) WhenErr[T]
- func (w WhenErr[T]) IfGetErr(condition bool, tru func() (T, error)) WhenErr[T]
- func (w WhenErr[T]) Other(condition func() bool, tru func() T) WhenErr[T]
- func (w WhenErr[T]) OtherErr(condition func() bool, tru func() (T, error)) WhenErr[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type When ¶
type When[T any] struct { // contains filtered or unexported fields }
When is if...else expression builder
func If ¶
If builds use.If(condition, tru).Else(fals) expression builder. Looks like val := use.If(condition, valOnTrue).Else(defaltVal) tha can be rewrited by:
var val type if condtion { val = valOnTrue } else { val = defaltVal }
func IfOK ¶ added in v0.0.13
IfOK like If but with reverse arguments order. It is useful for wrapping calls of methods that return a value and a bool validity indicator.
func (When[T]) ElseGet ¶
func (w When[T]) ElseGet(fals func() T) T
ElseGet returns the tru or a return of the fals function according to the condition
func (When[T]) ElseGetErr ¶
ElseGetErr returns the success result or a result of the fals function according to the condition
func (When[T]) ElseZero ¶
func (w When[T]) ElseZero() (out T)
ElseZero evaluates expression and returns zero value as default
func (When[T]) Eval ¶
Eval evaluates the expression and returns ok==false if there is no satisfied condition
func (When[T]) Or ¶ added in v0.0.10
Or returns the current condition 'w' if true, or 'another' otherwise
type WhenErr ¶
type WhenErr[T any] struct { // contains filtered or unexported fields }
WhenErr if..else expression builder
func (WhenErr[T]) ElseGet ¶
ElseGet returns the tru or a return of the fals function according to the condition
func (WhenErr[T]) ElseGetErr ¶
ElseGetErr returns the success result or a result of the fals function according to the condition
func (WhenErr[T]) ElseZero ¶ added in v0.0.9
ElseZero evaluates expression and returns zero value as default
func (WhenErr[T]) Eval ¶ added in v0.0.9
Eval evaluates the expression and returns ok==false if there is no satisfied condition
func (WhenErr[T]) IfGetErr ¶
IfGetErr creates new condition branch for an error return getter function