util

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Opt

type Opt[T any] struct {
	// contains filtered or unexported fields
}

Type-safe nullable types. Provides a safe way to manipulate values that may be null. It is nestable.

func None

func None[T any]() Opt[T]

Constructing an Option without a value

func Some

func Some[T any](a T) Opt[T]

Constructing an Option with a value.

func (Opt[T]) IfNone

func (a Opt[T]) IfNone(action func())

Execute the action when ok is false.

func (Opt[T]) IfSome

func (a Opt[T]) IfSome(action func(value T))

Execute the action when ok is true.

func (Opt[T]) IsNone

func (a Opt[T]) IsNone() bool

Returns true when ok is false.

func (Opt[T]) IsSome

func (a Opt[T]) IsSome() bool

Returns true when ok is true.

func (Opt[T]) Next

func (a Opt[T]) Next() Opt[T]

func (Opt[T]) Or

func (a Opt[T]) Or(value T) T

Get the value in an safe way, and get else value when ok is false.

func (Opt[T]) OrDefault

func (a Opt[T]) OrDefault() (v T)

Get the value in an safe way, and get else value when ok is false.

func (Opt[T]) OrPanic

func (a Opt[T]) OrPanic() T

Get the value in an unsafe way, and execute panic when ok is false.

func (Opt[T]) Val

func (a Opt[T]) Val() (value T, ok bool)

Val can use go's customary deconstructed Option, which is used like the built-in map, and can safely use value when ok is true.

type Pair

type Pair[T1 any, T2 any] struct {
	First  T1
	Second T2
}

Pair is a combination type containing two elements.

func PairOf

func PairOf[T1 any, T2 any](f T1, s T2) Pair[T1, T2]

Constructing a Pair with two parameters.

func (Pair[T1, T2]) Val

func (a Pair[T1, T2]) Val() (T1, T2)

Val can use go's customary deconstructed Pair, which is used like the built-in map.

type Ref

type Ref[T any] struct {
	// contains filtered or unexported fields
}

func RefOf

func RefOf[T any](v *T) Ref[T]

func (Ref[T]) Get

func (a Ref[T]) Get() T

func (Ref[T]) IsNil

func (a Ref[T]) IsNil() bool

func (Ref[T]) IsNotNil

func (a Ref[T]) IsNotNil() bool

func (Ref[T]) Set

func (a Ref[T]) Set(v T) T

func (Ref[T]) Val

func (a Ref[T]) Val() (v T, ok bool)

type Result

type Result[T any] struct {
	// contains filtered or unexported fields
}

Type-safe errorable types. Provides a safe way to manipulate values that may be error. It is nestable.

func Err

func Err[T any](a error) Result[T]

Constructing an Result with a error value.

func Ok

func Ok[T any](a T) Result[T]

Constructing an Result with a success value.

func (Result[T]) IfErr

func (a Result[T]) IfErr(action func(err error))

Execute the action when error is not nil.

func (Result[T]) IfOk

func (a Result[T]) IfOk(action func(value T))

Execute the action when error is nil.

func (Result[T]) IsErr

func (a Result[T]) IsErr() bool

Returns true when error is not nil.

func (Result[T]) IsOk

func (a Result[T]) IsOk() bool

Returns true when error is nil.

func (Result[T]) Or

func (a Result[T]) Or(value T) T

Get the value in an safe way, and get else value when error is not nil.

func (Result[T]) OrDefault

func (a Result[T]) OrDefault() (v T)

func (Result[T]) OrPanic

func (a Result[T]) OrPanic() T

Get the value in an unsafe way, and execute panic when error is not nil.

func (Result[T]) Val

func (a Result[T]) Val() (value T, err error)

Val can use go's customary deconstructed Result, which is used like the built-in map, and can safely use value when error is nil.

type Void

type Void struct{}

Indicates the type of empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL