opt

package
v0.0.0-...-762a710 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chain

func Chain[A, B any](fn func(a A) Option[B]) func(Option[A]) Option[B]

Execute a function that returns an Option on the Option value if it exists. Otherwise return the empty Option itself

func Exists

func Exists[T any](predicate func(value T) bool) func(Option[T]) bool

Returns `false` if `None` or returns the boolean result of the application of the given predicate to the `Some` value

func FromPredicate

func FromPredicate[T any](predicate func(value T) bool) func(T) Option[T]

Constructor of Option from a predicate. Returns a None if the predicate function over the value return false. Returns a Some if the predicate function over the value return true.

func GetOrElse

func GetOrElse[T any](onNone fp.Lazy[T]) func(Option[T]) T

Extracts the value out of the Option, if it exists. Otherwise returns the function with a default value

func IsNone

func IsNone[T any](o Option[T]) bool

Helper to check if the Option is missing the value

func IsSome

func IsSome[T any](o Option[T]) bool

Helper to check if the Option has a value

func Map

func Map[T, R any](fn func(value T) R) func(o Option[T]) Option[R]

Execute the function on the Option value if it exists. Otherwise return the empty Option itself

func Match

func Match[T, R any](onNone fp.Lazy[R], onSome func(value T) R) func(Option[T]) R

Extracts the value out of the Option, if it exists, with a function. Otherwise returns the function with a default value

Types

type Option

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

Base struct

func Flatten

func Flatten[T any](o Option[Option[T]]) Option[T]

Removes one level of nesting. Returns its bound argument into the outer level.

func FromError

func FromError[R any](value R, e error) Option[R]

Constructor of Option from any couple of mutually exclusive `value` and `error`. Returns a None in case we have an error, Some if we have a value and error is nil.

func FromErrorFn

func FromErrorFn[R any](fn func() (value R, e error)) Option[R]

Constructor of Option from any lazy function that returns a couple of mutually exclusive `value` and `error`. Returns a None in case we have a return error, Some if we have return value and error is nil.

func None

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

Constructor for Option without a value

func Some

func Some[T any](value T) Option[T]

Constructor for Option with a value

Jump to

Keyboard shortcuts

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