towhee.functional.option.Empty¶
- class towhee.functional.option.Empty(x: Optional[Any] = None, e: Optional[Exception] = None)[source]¶
Bases:
Option
[A
]Empty value for Option
- Parameters:
x (Any, optional) – The value. Defaults to None.
e (Exception, optional) – The reasone for value. Defaults to None.
Methods
Return an empty value.
Apply boxed version of callable.
Return the reason of the empty value.
Return unboxed value, or default if the value is empty.
Return True if the value is empty.
Return True if the value is boxed value.
Apply a function to a value.
Return a boxed value.
- __repr__() str [source]¶
The repr function that returns default ‘Empty()’.
- Returns:
Returns ‘Empty()’.
- Return type:
str
- flat_map(f: Callable[[A], Option[B]]) Option[B] [source]¶
Apply boxed version of callable.
- Parameters:
f (Callable[[A], Option[B]]) – Boxed version of callable
- Returns:
The boxed value.
- Return type:
Option[B]
Examples
>>> Option.of(1).flat_map(lambda x: x+1) 2
>>> Option.empty().flat_map(lambda x: x+1) Empty()
- get()[source]¶
Return the reason of the empty value.
- Returns:
Reason for empty.
- Return type:
_Reason
- get_or_else(default)¶
Return unboxed value, or default if the value is empty.
- Parameters:
default (any) – The default value to return.
- Returns:
The unboxed value, or default if empty.
- Return type:
any
Examples
>>> Option.of(0).get_or_else(1) 0
>>> Option.empty().get_or_else(1) 1
- is_empty()¶
Return True if the value is empty.
- Returns:
True if empty.
- Return type:
bool
- is_some()¶
Return True if the value is boxed value.
- Returns:
True if boxed.
- Return type:
bool