option

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package option is the presence type of G++: a value that is there (Some) or absent (None). It is authored in G++ and distributed as generated Go — consumers never need the gpp toolchain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fold

func Fold[T any, R any](o Option[T], cs OptionCases[T, R]) R

Fold reduces Option[T] by one-level case analysis.

func Get

func Get[T any](o Option[T]) (T, bool)

Get leaves in Go's comma-ok shape.

func IsNone

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

IsNone reports absence.

func IsSome

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

IsSome reports presence.

func UnwrapOr

func UnwrapOr[T any](o Option[T], fallback T) T

UnwrapOr yields the value or a fallback.

Types

type None

type None[T any] struct{}

type Option

type Option[T any] interface {
	// contains filtered or unexported methods
}

Option carries at most one value.

func Bind

func Bind[T any, U any](o Option[T], f func(T) Option[U]) Option[U]

Bind chains an option-producing function; None bypasses it.

func Map

func Map[T any, U any](o Option[T], f func(T) U) Option[U]

Map lifts a plain function over the value; None passes through.

func Of

func Of[T any](v T, ok bool) Option[T]

Of enters from Go's comma-ok shape.

func OrElse

func OrElse[T any](o Option[T], alt Option[T]) Option[T]

OrElse yields the option itself when present, otherwise the alternative.

type OptionCases

type OptionCases[T any, R any] struct {
	Some func(value T) R
	None func() R
}

OptionCases selects one handler per Option variant for Fold.

type Some

type Some[T any] struct {
	Value T
}

Jump to

Keyboard shortcuts

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