either

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package either provides a sum type representing a value of one of two types.

Convention: Left represents failure/error, Right represents success. Mnemonic: "Right is right" (correct).

Either is right-biased: Map operates on the Right value only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fold

func Fold[L, R, T any](e Either[L, R], onLeft func(L) T, onRight func(R) T) T

Fold applies onLeft if e is Left, or onRight if e is Right.

Types

type Either

type Either[L, R any] struct {
	// contains filtered or unexported fields
}

Either represents a value of one of two types. Convention: Left for failure, Right for success.

func Left

func Left[L, R any](l L) Either[L, R]

Left returns a Left Either containing l.

func Right[L, R any](r R) Either[L, R]

Right returns a Right Either containing r.

func (Either[L, R]) Get

func (e Either[L, R]) Get() (_ R, _ bool)

Get returns the Right value and true, or zero and false if Left.

func (Either[L, R]) GetLeft

func (e Either[L, R]) GetLeft() (_ L, _ bool)

GetLeft returns the Left value and true, or zero and false if Right.

func (Either[L, R]) GetOrElse

func (e Either[L, R]) GetOrElse(defaultVal R) R

GetOrElse returns the Right value, or defaultVal if Left.

func (Either[L, R]) IsLeft

func (e Either[L, R]) IsLeft() bool

IsLeft reports whether e is a Left.

func (Either[L, R]) IsRight

func (e Either[L, R]) IsRight() bool

IsRight reports whether e is a Right.

func (Either[L, R]) LeftOrElse

func (e Either[L, R]) LeftOrElse(defaultVal L) L

LeftOrElse returns the Left value, or defaultVal if Right.

func (Either[L, R]) Map

func (e Either[L, R]) Map(fn func(R) R) Either[L, R]

Map applies fn to the Right value and returns a new Either. If e is Left, returns e unchanged.

Jump to

Keyboard shortcuts

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