Documentation
¶
Index ¶
- func All(conditions ...bool) bool
- func LazyTernary[T any](condition bool, fnTrue, fnFalse func() T) T
- func Ternary[T any](condition bool, resultTrue, resultFalse T) T
- func Unless(condition bool, fn func())
- func When(condition bool, fn func())
- type Atomic
- type Failure
- type None
- type Optional
- type Result
- type Some
- type Success
- type Void
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LazyTernary ¶ added in v0.0.4
LazyTernary evaluates a boolean condition and executes one of two functions, returning its result.
func Ternary ¶ added in v0.0.4
Ternary evaluates a boolean condition and returns one of two values.
Types ¶
type Atomic ¶ added in v0.0.3
type Atomic[T any] struct { // contains filtered or unexported fields }
Atomic is a type-safe atomic value container. The zero value is the zero value of T. An Atomic must not be copied after first use.
func (*Atomic[T]) CompareAndSwap ¶ added in v0.0.3
CompareAndSwap executes the compare-and-swap operation for x. It returns true if the swap was successful (old matched the current value), false otherwise.
func (*Atomic[T]) Load ¶ added in v0.0.3
func (s *Atomic[T]) Load() T
Load atomically loads and returns the value stored in x. If the stored value is not of type T, returns the zero value of T.
type Failure ¶ added in v0.0.2
type Failure[T any] struct { // contains filtered or unexported fields }
Failure struct represents a failed outcome wrapping an error within a Result container.
type None ¶
type None[T any] struct{}
None represents an Optional instance that does not contain any value.
func (*None[T]) Get ¶
func (n *None[T]) Get() T
Get always returns the zero value of type T since None contains no value.
type Optional ¶
type Optional[T any] interface { // IsPresent returns true if there is a value present, otherwise false. IsPresent() bool // IsEmpty returns true if there is no value present, otherwise false. IsEmpty() bool // Get returns the value if present. If no value is present, it returns the zero value of type T. Get() T }
Optional represents a container object which may or may not contain a non-nil value. It provides a type-safe alternative to using nil pointers.
type Result ¶ added in v0.0.2
type Result[T any] interface { // IsSuccess returns true if the operation completed successfully, otherwise false. IsSuccess() bool // IsFailure returns true if the operation failed with an error, otherwise false. IsFailure() bool // Value returns the success value if present, or the zero value of type T. Value() T // Error returns the underlying error if it failed, or nil. Error() error }
Result represents the outcome of an operation that can either succeed with a value of type T or fail with an error. It wraps the standard built-in error type.
func NewFailure ¶ added in v0.0.2
NewFailure creates and returns a new failed Result containing the provided error.
func NewSuccess ¶ added in v0.0.2
NewSuccess creates and returns a new successful Result containing the provided value.
type Some ¶
type Some[T any] struct { // contains filtered or unexported fields }
Some represents an Optional instance that contains a value.
func (*Some[T]) Get ¶
func (s *Some[T]) Get() T
Get returns the underlying value. If the receiver is nil, it returns the zero value of type T.
type Success ¶ added in v0.0.2
type Success[T any] struct { // contains filtered or unexported fields }
Success struct represents a successful outcome within a Result container.