either

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 1 Imported by: 2

Documentation

Overview

Package either provides a simple implementation of a sum type, Either, that can be either a Left or a Right.

Usage:

left := LeftOf[string](42)
fmt.Println(left.Get()) // 42

right := RightOf[int]("foo")
fmt.Println(right.Get()) // foo

var either Either[int, string] = left
either = right

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Either

type Either[L, R any] interface {
	String() string
	GoString() string
	// contains filtered or unexported methods
}

Either is a "sum type" that can be either Left or Right.

type Left

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

func LeftOf

func LeftOf[R, L any](value L) Left[L, R]

LeftOf creates an Either[L, R] with a left value.

Note that the L and R type parameters are flipped so that we can use type inference to avoid having to specify the L type.

func (Left[L, R]) Get

func (e Left[L, R]) Get() L

func (Left[L, R]) GoString

func (e Left[L, R]) GoString() string

func (Left[L, R]) String

func (e Left[L, R]) String() string
type Right[L, R any] struct {
	// contains filtered or unexported fields
}

func RightOf

func RightOf[L, R any](value R) Right[L, R]

RightOf creates an Either[L, R] with a right value.

func (Right[L, R]) Get

func (e Right[L, R]) Get() R

func (Right[L, R]) GoString

func (e Right[L, R]) GoString() string

func (Right[L, R]) String

func (e Right[L, R]) String() string

Jump to

Keyboard shortcuts

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