Result Types

Result type for pipeline error handling — Rust-inspired Ok/Err.

Provides a discriminated union for representing success (Ok) or failure (Err) as values that flow through pipeline channels, instead of silently dropping errors.

Works with Python 3.12+ match/case:

match item:
        case Ok(value=v):
                print(f"Success: {v}")
        case Err(error=e):
                print(f"Failed at {e.stage}: {e.exception}")
class anyiostream.result.PipelineError[source]

Bases: object

Context captured when a pipeline stage raises an exception.

exception

The caught exception instance.

Type:

Exception

item

The original input item that caused the error.

Type:

Any

stage

Human-readable label of the stage that failed.

Type:

str | None

traceback

Formatted traceback string at the point of failure.

Type:

str | None

exception: Exception
item: Any
stage: str | None
traceback: str | None
__init__(exception, item=None, stage=None, traceback=None)
Parameters:
Return type:

None

class anyiostream.result.Ok[source]

Bases: Generic

Successful result wrapping a value.

value: T
is_ok()[source]
Return type:

bool

is_err()[source]
Return type:

bool

unwrap()[source]

Return the contained value.

Return type:

T

unwrap_or(default)[source]

Return the contained value (ignores default).

Parameters:

default (T)

Return type:

T

unwrap_err()[source]

Raises — an Ok has no error.

Return type:

NoReturn

map(func)[source]

Apply func to the contained value.

Parameters:

func (Any)

Return type:

Ok[Any]

map_err(func)[source]

No-op — Ok has no error to transform.

Parameters:

func (Any)

Return type:

Ok[T]

__init__(value)
Parameters:

value (T)

Return type:

None

class anyiostream.result.Err[source]

Bases: Generic

Error result wrapping an error.

error: E
is_ok()[source]
Return type:

bool

is_err()[source]
Return type:

bool

unwrap()[source]

Raises — an Err has no value.

Return type:

NoReturn

unwrap_or(default)[source]

Return default since Err has no value.

Parameters:

default (Any)

Return type:

Any

unwrap_err()[source]

Return the contained error.

Return type:

E

map(func)[source]

No-op — Err has no value to transform.

Parameters:

func (Any)

Return type:

Err[E]

map_err(func)[source]

Apply func to the contained error.

Parameters:

func (Any)

Return type:

Err[Any]

__init__(error)
Parameters:

error (E)

Return type:

None

type anyiostream.result.Result = Ok | Err

Rust-inspired Ok/Err discriminated union for pipeline error handling.

Ok[T]

Wraps a successful value.

from anyiostream import Ok

ok = Ok(42)

Methods

Method

Returns

Description

.value

T

The wrapped value

.is_ok()

True

Always true for Ok

.is_err()

False

Always false for Ok

.unwrap()

T

Return the value

.unwrap_or(default)

T

Return the value (ignores default)

.unwrap_err()

raises ValueError

Ok has no error

.map(fn)

Ok[U]

Apply fn to value

.map_err(fn)

Ok[T]

No-op for Ok

Err[E]

Wraps an error value.

from anyiostream import Err, PipelineError

err = Err(PipelineError(exception=ValueError("boom"), item=42, stage="parse"))

Methods

Method

Returns

Description

.error

E

The wrapped error

.is_ok()

False

Always false for Err

.is_err()

True

Always true for Err

.unwrap()

raises ValueError

Err has no value

.unwrap_or(default)

default

Return the default

.unwrap_err()

E

Return the error

.map(fn)

Err[E]

No-op for Err

.map_err(fn)

Err[U]

Apply fn to error

PipelineError

Context captured when a pipeline stage raises an exception.

from anyiostream import PipelineError

Fields

Field

Type

Description

exception

Exception

The caught exception

item

Any

The input item that caused the error

stage

str | None

Stage name (from name= parameter)

traceback

str | None

Formatted traceback at failure point

String Representation

str(err.error)  # "[parse] ValueError: boom"

Result Type Alias

Result = Ok[T] | Err[E]

Pattern Matching

match item:
    case Ok(value=v):
        print(f"Success: {v}")
    case Err(error=e):
        print(f"Failed at {e.stage}: {e.exception}")

Both Ok and Err are frozen dataclasses with slots=True, supporting structural pattern matching in Python 3.12+.