Skip to content

Result API

fpstreams.Result

Bases: Generic[T]

A container for a value that represents either a successful result (Success) or a failure (Failure). Replaces try/except blocks in functional pipelines.

error property

Returns the exception if this is a Failure, otherwise None.

failure(error) classmethod

Creates a failed Result.

flat_map(mapper)

If Success, returns the result of applying the mapper (which must return a Result). If Failure, returns the existing Failure.

get_or_else(default)

Returns the value if Success, or the default value if Failure.

get_or_throw()

Returns the value if Success, otherwise raises the stored exception.

map(mapper)

If Success, applies the mapper to the value. If Failure, returns the existing Failure (skips the mapper).

map_error(mapper)

If Failure, allows you to transform the exception. If Success, does nothing.

of(func) classmethod

Executes the provided function. Returns Success(value) if it works, or Failure(exception) if it crashes.

on_failure(action)

Executes action if Failure.

on_success(action)

Executes action if Success.

success(value) classmethod

Creates a successful Result.