Add <= as an alias for map

This commit is contained in:
Emi Simpson 2023-03-05 19:44:28 -05:00
parent 4b4f9037cf
commit 3028075176
Signed by: Emi
GPG Key ID: A12F2C2FFDC3D847
1 changed files with 6 additions and 0 deletions

View File

@ -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]: