fumus.utils.optional ==================== .. py:module:: fumus.utils.optional Classes ------- .. autoapisummary:: fumus.utils.optional.Optional Module Contents --------------- .. 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__()