either

package
v2.14.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package either implements a simple generic "Either" type that can represent exactly one value out of two options.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type E

type E[A any, B any] struct {
	// contains filtered or unexported fields
}

E represents a type that can hold either a value "a" of type A or a value "b" of type B.

func A

func A[A any, B any](a A) E[A, B]

A returns a new E that holds a value "a" of Type A.

func B

func B[A any, B any](b B) E[A, B]

B returns a new E that holds a value "b" of type B.

func Pack

func Pack[A any, B any](a A, b B, index byte) E[A, B]

Pack returns an E that contains eotjer a value "a" of type A (if index == 'a'), a value "b" of type B (if index == 'b'), or panics if index is not 'a' or 'b'.

func (E[A, B]) A

func (e E[A, B]) A() (result A, ok bool)

A returns the value "a" of type A and true if the E contains that value, or the zero value and false otherwise.

func (E[A, B]) B

func (e E[A, B]) B() (result B, ok bool)

B returns the value "b" of type B and true if the E contains that value, or the zero value and false otherwise.

func (E[A, B]) Unpack

func (e E[A, B]) Unpack() (A, B, byte)

Unpack returns the components of an E. The last return value is a discriminator with the value 'a' or 'b' representing the existence of the value "a" of type A or the value "b" of type B.

Jump to

Keyboard shortcuts

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