option

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package option contains Option[A] implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fold

func Fold[A any, B any](oa Option[A], f func(A) B, g func() B) (b B)

Fold transforms all possible values of OptionA using two provided functions.

func ForEach added in v0.2.6

func ForEach[A any](oa Option[A], f func(A))

ForEach runs the given function on the value if it's available.

func Get

func Get[A any](oa Option[A]) A

Get is an unsafe function that unwraps the value from the option.

func IsDefined added in v0.2.6

func IsDefined[A any](oa Option[A]) bool

IsDefined checks whether the option contains a value.

func IsEmpty added in v0.2.6

func IsEmpty[A any](oa Option[A]) bool

IsEmpty checks whether the option is empty.

Types

type Option

type Option[A any] struct {
	ValueOrNil *A
}

Option[A] can represent a value or an absent value of type A.

func Filter

func Filter[A any](oa Option[A], predicate func(A) bool) Option[A]

Filter leaves the value inside option only if predicate is true.

func FlatMap

func FlatMap[A any, B any](oa Option[A], f func(A) Option[B]) Option[B]

FlatMap converts an internal value if it is present using the provided function.

func Flatten

func Flatten[A any](ooa Option[Option[A]]) Option[A]

Flatten simplifies option of option to just Option[A].

func Map

func Map[A any, B any](oa Option[A], f func(A) B) Option[B]

Map applies a function to the value inside option if any.

func None

func None[A any]() Option[A]

None constructs an option without value.

func Some

func Some[A any](a A) Option[A]

Some constructs an option with value.

Jump to

Keyboard shortcuts

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