result

package
v0.212.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package result is the railway type of Go+: a computation that either produced a value (Ok) or failed (Err). It is authored in Go+ and distributed as generated Go — consumers never need the goplus toolchain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fold

func Fold[T any, E any, R any](v Result[T, E], cs ResultCases[T, E, R]) R

Fold reduces Result[T, E] by one-level case analysis.

func IsErr

func IsErr[T any, E any](r Result[T, E]) bool

IsErr reports whether the Result is on the failure track.

func IsOk

func IsOk[T any, E any](r Result[T, E]) bool

IsOk reports whether the Result is on the success track.

func Unpack

func Unpack[T any, E any](r Result[T, E]) (T, E)

Unpack leaves the railway in Go shape: Ok yields (value, nil); Err yields (zero, err).

func UnwrapOr

func UnwrapOr[T any, E any](r Result[T, E], fallback T) T

UnwrapOr yields the Ok value or a fallback.

Types

type Err

type Err[T any, E any] struct {
	Err E
}

type Ok

type Ok[T any, E any] struct {
	Value T
}

type Result

type Result[T any, E any] interface {
	// contains filtered or unexported methods
}

Result carries one success value or one failure value.

func Bind

func Bind[T any, E any, U any](r Result[T, E], f func(T) Result[U, E]) Result[U, E]

Bind connects a switch function onto the railway: applied to the Ok value; an Err bypasses it.

func Map

func Map[T any, E any, U any](r Result[T, E], f func(T) U) Result[U, E]

Map lifts a plain function onto the success track.

func MapError

func MapError[T any, E any, F any](r Result[T, E], f func(E) F) Result[T, F]

MapError transforms the failure track.

func Of

func Of[T any](v T, err error) Result[T, error]

Of enters the railway from a Go-shaped pair.

func Tee

func Tee[T any, E any](r Result[T, E], f func(T)) Result[T, E]

Tee runs a dead-end function on the Ok value and passes the Result through unchanged; an Err bypasses it.

type ResultCases

type ResultCases[T any, E any, R any] struct {
	Ok  func(value T) R
	Err func(err E) R
}

ResultCases selects one handler per Result variant for Fold.

Jump to

Keyboard shortcuts

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