fp
Bad
¶
Bases: Generic[B, G]
The bad side of the disjoint union.
Source code in m/core/fp.py
__init__(value)
¶
Initialize a Bad
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
B
|
The "bad" value to store in the instance. |
required |
__iter__()
¶
Iterate over values of an instance.
The intention is to raise a StopBadIteration
exception to
be able to break out of for loop comprehensions.
Raises:
Type | Description |
---|---|
StopBadIteration
|
If the instance has a "Bad" value. |
Source code in m/core/fp.py
flat_map_bad(fct)
¶
Apply the input function if this is a Bad
value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fct |
Callable[[B], OneOf[B, G]]
|
The function to apply to the "Bad" value. |
required |
Returns:
Type | Description |
---|---|
OneOf[B, G]
|
Itself if its a |
Source code in m/core/fp.py
get_or_else(default)
¶
Return the value if its Good or the given argument if its a Bad.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default |
LazyArg[G]
|
The default value in case the instance is "Bad". |
required |
Returns:
Type | Description |
---|---|
G
|
Either the value or the default specified by "default". |
Source code in m/core/fp.py
iter()
¶
Shortcut to transform to a list.
Can be used as list(x.iter())
. It will either contain a value or be
an empty list.
Yields:
Type | Description |
---|---|
G
|
The value if the instance is a "Good" value. |
map(_fct)
¶
Apply the function to its value if this is a Good
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_fct |
Callable[[G], K]
|
The function to apply to the "Good" value. |
required |
Returns:
Type | Description |
---|---|
'Bad[B, K]'
|
Itself if its a |
Source code in m/core/fp.py
Good
¶
Bases: Generic[B, G]
The good side of the disjoint union.
Source code in m/core/fp.py
__init__(value)
¶
Initialize a Good
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
G
|
The "good" value to store in the instance. |
required |
__iter__()
¶
flat_map_bad(_fct)
¶
Apply the input function if this is a Bad
value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_fct |
Callable[[B], OneOf[B, G]]
|
The function to apply to the "Bad" value. |
required |
Returns:
Type | Description |
---|---|
OneOf[B, G]
|
Itself if its a |
Source code in m/core/fp.py
get_or_else(_default)
¶
Return the value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_default |
LazyArg[G]
|
The default value in case the instance is "Bad". |
required |
Returns:
Type | Description |
---|---|
G
|
Either the value or the default specified by "default". |
iter()
¶
Shortcut to transform to a list.
Can be used as list(x.iter())
. It will either contain a value or be
an empty list.
Yields:
Type | Description |
---|---|
G
|
The value if the instance is a "Good" value. |
Source code in m/core/fp.py
map(fct)
¶
Apply the function to its value if this is a Good
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fct |
Callable[[G], K]
|
The function to apply to the "Good" value. |
required |
Returns:
Type | Description |
---|---|
'Good[B, K]'
|
Itself if its a |
Source code in m/core/fp.py
StopBadIteration
¶
is_bad(inst)
¶
Assert that a OneOf instance is a Bad
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inst |
OneOf[B, G]
|
The |
required |
Returns:
Type | Description |
---|---|
TypeGuard[Bad[B, G]]
|
True if the instance is a |
Source code in m/core/fp.py
is_good(inst)
¶
Assert that a OneOf instance is a Good
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inst |
OneOf[B, G]
|
The |
required |
Returns:
Type | Description |
---|---|
TypeGuard[Good[B, G]]
|
True if the instance is a |
Source code in m/core/fp.py
lazy_arg(z_arg)
¶
Return the output of calling z_arg
if it is function.
Otherwise param is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z_arg |
LazyArg[A]
|
A function or a value |
required |
Returns:
Type | Description |
---|---|
A
|
The value. |