catch

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package catch implements the catch-by-type combinators (CatchAs, CatchIs, MapErrorAs and TapErrorAs) once for all monads whose error channel is error. Each monad passes in its own ChainLeft, TapLeft, MapLeft and Left.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CatchAs

func CatchAs[E error, HKTB, OP any](
	chainLeft func(func(error) HKTB) OP,
	fromLeft func(error) HKTB,
	f func(E) HKTB,
) OP

CatchAs recovers from errors of type E with f.

func CatchIs

func CatchIs[HKTB, OP any](
	chainLeft func(func(error) HKTB) OP,
	fromLeft func(error) HKTB,
	target error,
	f func(error) HKTB,
) OP

CatchIs recovers from errors that match target with f.

func ErrorAs

func ErrorAs[E error](err error) ET.Either[error, E]

ErrorAs returns the E found in the chain of err as the Right value, or err itself as the Left value.

func ErrorIs

func ErrorIs(target error) func(error) ET.Either[error, error]

ErrorIs returns a function that returns err as the Right value if errors.Is(err, target) holds, and as the Left value otherwise.

func MapAs

func MapAs[E error](f func(E) error) func(error) error

MapAs returns an error mapping that replaces errors of type E by f applied to them and keeps all other errors.

func MapErrorAs

func MapErrorAs[E error, OP any](
	mapLeft func(func(error) error) OP,
	f func(E) error,
) OP

MapErrorAs replaces errors of type E by f applied to them.

func OnMatch

func OnMatch[E, HKTB any](
	fromLeft func(error) HKTB,
	match func(error) ET.Either[error, E],
	f func(E) HKTB,
) func(error) HKTB

OnMatch returns an error handler that applies f to the errors selected by match and fails with the original error otherwise.

func OnMatchI

func OnMatchI[E, B any](
	match func(error) ET.Either[error, E],
	f func(E) (B, error),
) func(error) (B, error)

OnMatchI is the variant of OnMatch for handlers that return a (value, error) tuple. It returns the zero value and the original error for the errors not selected by match.

func TapErrorAs

func TapErrorAs[E error, HKTB, OP any](
	tapLeft func(func(error) HKTB) OP,
	fromLeft func(error) HKTB,
	f func(E) HKTB,
) OP

TapErrorAs runs f for its side effect on errors of type E and keeps the original error.

Types

This section is empty.

Directories

Path Synopsis
Package catchtest is a shared test suite for the error channel of the monads whose error type is error: the catch-by-type combinators (CatchAs, CatchIs, MapErrorAs, TapErrorAs) and the primitives they build on (ChainLeft, OrElse, MapLeft, ChainFirstLeft, TapLeft).
Package catchtest is a shared test suite for the error channel of the monads whose error type is error: the catch-by-type combinators (CatchAs, CatchIs, MapErrorAs, TapErrorAs) and the primitives they build on (ChainLeft, OrElse, MapLeft, ChainFirstLeft, TapLeft).

Jump to

Keyboard shortcuts

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