fumus.utils.optional
Classes
Container object which may (or may not) contain a non-null value |
Module Contents
- class fumus.utils.optional.Optional(element)[source]
Container object which may (or may not) contain a non-null value
- __slots__ = ('_element',)
- _element
- classmethod of_nullable(element)[source]
Returns an Optional describing the given value, if non-null, otherwise returns an empty Optional
- property is_present
Returns bool whether a value is present
- property is_empty
Returns bool whether the Optional is 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)