fumus.utils =========== .. py:module:: fumus.utils Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/fumus/utils/dict_item/index /autoapi/fumus/utils/optional/index /autoapi/fumus/utils/result/index Classes ------- .. autoapisummary:: fumus.utils.DictItem fumus.utils.Optional fumus.utils.Result Package Contents ---------------- .. py:class:: DictItem(key, value) Helper record class for mapping key-value pairs .. py:attribute:: _key .. py:attribute:: _value .. py:property:: key .. py:property:: value .. py:method:: _map(val) .. py:method:: __repr__() .. py:method:: __eq__(other) .. py:method:: __hash__() .. py:class:: Optional(element) Container object which may (or may not) contain a non-null value .. py:attribute:: __slots__ :value: ('_element',) .. py:attribute:: _element .. py:method:: empty() :classmethod: Creates empty Optional .. py:method:: of(element) :classmethod: Creates Optional describing given non-null value .. py:method:: of_nullable(element) :classmethod: Returns an Optional describing the given value, if non-null, otherwise returns an empty Optional .. py:method:: get() If a value is present, returns the value, otherwise raises an Exception .. py:property:: is_present Returns bool whether a value is present .. py:property:: is_empty Returns bool whether the Optional is empty .. py:method:: if_present(action) Performs given action with the value if the Optional is not empty .. py:method:: if_present_or_else(action, empty_action) Performs given action with the value if the Optional is not empty, otherwise calls fallback 'empty_action' .. py:method:: or_else(value) Returns the value if present, or a provided argument otherwise. Safe alternative to get() method .. py:method:: or_else_get(supplier) Returns the value if present, or calls a 'supplier' function otherwise. Safe alternative to get() method .. py:method:: or_else_raise(supplier=None) Returns the value if present, otherwise throws an exception produced by the exception supplying function (if such is provided by the user) or NoSuchElementError .. py:method:: map(mapper) 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) .. py:method:: filter(predicate) If a value is present, and the value matches the given predicate, returns an Optional describing the value, otherwise returns an empty Optional .. py:method:: __repr__() .. py:method:: __eq__(other) .. py:method:: __hash__() .. py:class:: Result(value=None, error=None) .. py:attribute:: __slots__ :value: ('value', 'error') .. py:attribute:: value :value: None .. py:attribute:: error :value: None .. py:property:: is_successful Returns bool whether the Result is successful and an error is not present .. py:method:: success(value) :classmethod: Creates Result describing given value .. py:method:: failure(error) :classmethod: Creates Result describing given error .. py:method:: map_success(mapper) 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) .. py:method:: map_failure(mapper) 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 .. py:method:: map(on_success, on_failure) Combines map_success() and map_failure() .. py:method:: if_success(consumer) Performs given action with the value if the Result is successful .. py:method:: if_failure(consumer) Performs given action with the error if the Result is not successful .. py:method:: handle(on_success, on_failure) Combines if_success() and if_failure() .. py:method:: or_else(other) Returns the value if successful, or a provided argument otherwise .. py:method:: or_else_get(supplier) Returns the value if present, or calls a 'supplier' function otherwise .. py:method:: or_else_raise(supplier=None) 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 .. py:method:: __str__() .. py:method:: __eq__(other) .. py:method:: __hash__() .. py:method:: _map_result(mapper, arg) :staticmethod: