Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Either ¶
type Either[A, B any] interface { // contains filtered or unexported methods }
Either is the sum type for Either.
Example ¶
package main
import (
"fmt"
"github.com/calebcase/base/data/either"
"github.com/calebcase/base/data/list"
)
func main() {
l := either.Left[int, string]{1}
fmt.Println(l.Value)
r := either.Right[int, string]{"one"}
fmt.Println(r.Value)
{
es := list.List[either.Either[string, int]]{
either.Left[string, int]{"foo"},
either.Right[string, int]{3},
either.Left[string, int]{"bar"},
either.Right[string, int]{7},
either.Left[string, int]{"baz"},
}
fmt.Println(either.Lefts(es))
}
{
t := either.NewType[string, int]()
es := list.List[either.Either[string, int]]{
t.NewLeft("foo"),
t.NewRight(3),
t.NewLeft("bar"),
t.NewRight(7),
t.NewLeft("baz"),
}
fmt.Println(either.Lefts(es))
}
}
Output: 1 one [foo bar baz] [foo bar baz]
Click to show internal directories.
Click to hide internal directories.