Skip to content

Commit

Permalink
Fix issue with Either
Browse files Browse the repository at this point in the history
  • Loading branch information
ashuping committed Aug 12, 2024
1 parent e1011f9 commit 70a10be
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion modules/types/Either.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ def flat_map(self, f: Callable[[B], 'Either[A, C]']) -> 'Either[A, C]':
'''
...

def __eq__(self, other) -> bool:
''' Returns True iff both Eithers being compared are the same type (i.e.
both Left or both Right) AND the relevant inner values are the same.
'''
if self.is_right:
if not other.is_right:
return False

return self.val == other.val
else:
if other.is_right:
return False

return self.lval == other.lval



class Left[A](Either):
def __init__(self, val: A):
Expand Down Expand Up @@ -110,7 +126,7 @@ def is_right(self) -> bool:

@property
def val(self) -> B:
raise self.__rval
return self.__rval

@property
def lval(self) -> A:
Expand Down

0 comments on commit 70a10be

Please sign in to comment.