pyrio.utils.optional
Classes
Container object which may (or may not) contain a non-null value |
Module Contents
- class pyrio.utils.optional.Optional(element)
Container object which may (or may not) contain a non-null value
- _element
- __str__()
- static empty()
Creates empty Optional
- static of(element)
Creates Optional describing given non-null value
- static of_nullable(element)
Returns an Optional describing the given value, if non-null, otherwise returns an empty Optional
- get()
If a value is present, returns the value, otherwise raises an Exception
- is_present()
Returns bool whether a value is present
- is_empty()
Returns bool whether the Optional is empty
- if_present(action)
Performs given action with the value if the Optional is not empty
- if_present_or_else(action, empty_action)
Performs given action with the value if the Optional is not empty, otherwise calls fallback ‘empty_action’
- or_else(value)
Returns the value if present, or a provided argument otherwise. Safe alternative to get() method
- or_else_get(supplier)
Returns the value if present, or calls a ‘supplier’ function otherwise. Safe alternative to get() 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