opt

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: MIT Imports: 1 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chain

func Chain[A any, 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 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](option Option[T]) bool

Helper to check if the Option is missing the value

func IsSome

func IsSome[T any](option 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 {
	// contains filtered or unexported fields
}

Base option struct

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