fumus.utils

Submodules

Classes

DictItem

Helper record class for mapping key-value pairs

Optional

Container object which may (or may not) contain a non-null value

Result

Package Contents

class fumus.utils.DictItem(key, value)[source]

Helper record class for mapping key-value pairs

_key
_value
property key
property value
_map(val)[source]
__repr__()[source]
__eq__(other)[source]
__hash__()[source]
class fumus.utils.Optional(element)[source]

Container object which may (or may not) contain a non-null value

__slots__ = ('_element',)
_element
classmethod empty()[source]

Creates empty Optional

classmethod of(element)[source]

Creates Optional describing given non-null value

classmethod of_nullable(element)[source]

Returns an Optional describing the given value, if non-null, otherwise returns an empty Optional

get()[source]

If a value is present, returns the value, otherwise raises an Exception

property is_present

Returns bool whether a value is present

property is_empty

Returns bool whether the Optional is empty

if_present(action)[source]

Performs given action with the value if the Optional is not empty

if_present_or_else(action, empty_action)[source]

Performs given action with the value if the Optional is not empty, otherwise calls fallback ‘empty_action’

or_else(value)[source]

Returns the value if present, or a provided argument otherwise. Safe alternative to get() method

or_else_get(supplier)[source]

Returns the value if present, or calls a ‘supplier’ function otherwise. Safe alternative to get() method

or_else_raise(supplier=None)[source]

Returns the value if present, otherwise throws an exception produced by the exception supplying function (if such is provided by the user) or NoSuchElementError

map(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)

filter(predicate)[source]

If a value is present, and the value matches the given predicate, returns an Optional describing the value, otherwise returns an empty Optional

__repr__()[source]
__eq__(other)[source]
__hash__()[source]
class fumus.utils.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]