Source File
option.go
Belonging Package
go.pact.im/x/option
// Package option implements optional values to represent the lack of value// without pointers.package option// Of represents an optional value that may be nil.type Of[ any] struct {isSet boolvalue}// Value returns an option with the given value.func [ any]( ) Of[] {return Of[]{true, }}// Nil returns nil option with type T.func [ any]() Of[] {return Of[]{}}// Unwrap returns the underlying value and a boolean flag indicating whether it// is set.func ( Of[]) () (, bool) {return .value, .isSet}// UnwrapOrZero returns the option value or its zero value if it is not set.func [ any]( Of[]) {, := .Unwrap()if ! {varreturn}return}// IsNil returns true if the value is nil.func [ any]( Of[]) bool {return !.isSet}// Map applies function f to the underlying option value if it is set.func [, any]( Of[], func() ) Of[] {, := .Unwrap()if ! {return Nil[]()}return Value(())}
The pages are generated with Golds v0.7.6. (GOOS=linux GOARCH=amd64)