Add <= as an alias for map
This commit is contained in:
parent
4b4f9037cf
commit
3028075176
|
@ -589,6 +589,9 @@ class Ok(Generic[A, B]):
|
|||
def __lshift__(self, other: 'Callable[[A], Result[C, B]]') -> 'Result[C, B]':
|
||||
"Alias for bind"
|
||||
return other(self.val)
|
||||
def __le__(self, other: 'Callable[[A], C]') -> 'Result[C, B]':
|
||||
"Alias for map"
|
||||
return Ok(other(self.val))
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Err(Generic[A, B]):
|
||||
|
@ -612,6 +615,9 @@ class Err(Generic[A, B]):
|
|||
Err('oh noes!')
|
||||
"""
|
||||
return self #type:ignore
|
||||
def __le__(self, other: 'Callable[[A], C]') -> 'Result[C, B]':
|
||||
"Alias for map"
|
||||
return self #type:ignore
|
||||
Result = Ok[A, B] | Err[A, B]
|
||||
"A Result datatype, aka Either"
|
||||
def map_res(f: Callable[[A], C], r: Result[A, B]) -> Result[C, B]:
|
||||
|
|
Loading…
Reference in a new issue