Either
Either
Bases: Generic[L, R]
The Either class represents one of two cases: left or right. The left case
usually represents an error and is modeled by the
Left
class. The right case represents a
success and is modeled by the Right
class.
Either is a Monad
. It is parameterized by
two type variables: L and R. The type variable L is the value type of the
left case. The type variable R is the value type of the right case.
Either is monadic in the type varaible R.
Source code in funclift/types/either.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
flatmap(f)
abstractmethod
summary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
Callable[[R], Either[L, B]]
|
description |
required |
Returns:
Type | Description |
---|---|
Either[L, B]
|
Either[L, B]: description |
Source code in funclift/types/either.py
58 59 60 61 62 63 64 65 66 67 68 |
|
fmap(f)
abstractmethod
Need to repeat this to make mypy happy or else mypy will think the return type is Functor[B].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
Callable[[R], B]
|
description |
required |
Returns:
Type | Description |
---|---|
Either[L, B]
|
Either[L, B]: description |
Source code in funclift/types/either.py
44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
pure(a)
staticmethod
Creates a Right
instance to represent a success case whose value
is the passed-in parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a |
E
|
value of the success case. |
required |
Returns:
Type | Description |
---|---|
Right[E]
|
Right[E]: a |
Source code in funclift/types/either.py
31 32 33 34 35 36 37 38 39 40 41 42 |
|
Left
dataclass
Bases: Either[L, Any]
Left
Source code in funclift/types/either.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
Right
dataclass
Bases: Either[Any, A]
Right
Source code in funclift/types/either.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|