Documentation
¶
Overview ¶
Package types contains a collection of types and functions that are useful in Go.
Index ¶
- func Go[T any](f func() (T, error)) chan Result[T]
- type Option
- func (o Option[T]) Default(value T) T
- func (o Option[T]) Get() (T, bool)
- func (o Option[T]) GoString() string
- func (o Option[T]) MarshalJSON() ([]byte, error)
- func (o Option[T]) MustGet() T
- func (o Option[T]) Ok() bool
- func (o Option[T]) Ptr() *T
- func (o *Option[T]) Scan(src any) error
- func (o Option[T]) String() string
- func (o *Option[T]) UnmarshalJSON(data []byte) error
- func (o Option[T]) Value() (driver.Value, error)
- type Pair
- type Result
- type Triple
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
An Option type is a type that can contain a value or nothing.
func Ptr ¶ added in v0.5.0
Ptr returns an Option that returns None[T]() if the pointer is nil, otherwise the dereferenced pointer.
func Zero ¶ added in v0.8.0
func Zero[T comparable](value T) Option[T]
Zero returns an Option that returns None[T]() if the value is the zero value, otherwise the value.
func (Option[T]) Default ¶
func (o Option[T]) Default(value T) T
Default returns the Option value if it is present, otherwise it returns the value passed.
func (Option[T]) Get ¶
Get returns the value and a boolean indicating if the Option contains a value.
func (Option[T]) MarshalJSON ¶
func (Option[T]) MustGet ¶ added in v0.7.0
func (o Option[T]) MustGet() T
MustGet returns the value. It panics if the Option contains nothing.
func (Option[T]) Ptr ¶ added in v0.6.0
func (o Option[T]) Ptr() *T
Ptr returns a pointer to the value if the Option contains a value, otherwise nil.
func (*Option[T]) UnmarshalJSON ¶
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
A Result type is a type that can contain an error or a value.
func Outcome ¶
Outcome returns a Result that contains a value or an error.
It can be used to convert a function that returns a value and an error into a Result.
func (Result[T]) Default ¶
func (r Result[T]) Default(value T) T
Default returns the Result value if it is present, otherwise it returns the value passed.