fumus.utils.result

Classes

Result

Module Contents

class fumus.utils.result.Result(value=None, error=None)[source]
__slots__ = ('value', 'error')
value = None
error = None
property is_successful

Returns bool whether the Result is successful and an error is not present

classmethod success(value)[source]

Creates Result describing given value

classmethod failure(error)[source]

Creates Result describing given error

map_success(mapper)[source]

If a value is present, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result. Otherwise return an empty Optional. (NB: if the provided mapper returns an Optional, the result isn’t wrapped-up in an additional one)

map_failure(mapper)[source]

If an error is present, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result. Otherwise return an empty Optional

map(on_success, on_failure)[source]

Combines map_success() and map_failure()

if_success(consumer)[source]

Performs given action with the value if the Result is successful

if_failure(consumer)[source]

Performs given action with the error if the Result is not successful

handle(on_success, on_failure)[source]

Combines if_success() and if_failure()

or_else(other)[source]

Returns the value if successful, or a provided argument otherwise

or_else_get(supplier)[source]

Returns the value if present, or calls a ‘supplier’ function otherwise

or_else_raise(supplier=None)[source]

Returns the value if successful, otherwise throws an exception produced by the exception supplying function (if such is provided by the user) or re-raises original Exception

__str__()[source]
__eq__(other)[source]
__hash__()[source]
static _map_result(mapper, arg)[source]