def test_filter(self): assert filter_(lambda v: Right(v % 2 == 0), range(3)) == Right((0, 2))
def test_for_each(self): assert for_each(Right, range(3)) == Right((0, 1, 2))
def test_sequence(self): assert sequence([Right(v) for v in range(3)]) == Right((0, 1, 2))
def test_stack_safety(self): with recursion_limit(100): sequence([Right(v) for v in range(500)])
def test_bool(self, value): assert bool(Right(value)) assert not bool(Left(value))
def test_either_decorator(self): result_int = either(int) assert result_int('1') == Right(1)
def test_composition_law(self, f: Unary, g: Unary, value): h = compose(f, g) assert Left(value).map(h) == Left(value).map(g).map(f) assert Right(value).map(h) == Right(value).map(g).map(f)
def test_or_else(self, value, default): assert Right(value).or_else(default) == value assert Left(value).or_else(default) == default
def test_identity_law(self, value): assert Left(value).map(identity) == Left(value) assert Right(value).map(identity) == Right(value)
def test_inequality(self, first, second): assume(first != second) assert Left(first) != Left(second) assert Right(first) != Right(second) assert Left(first) != Right(first)
def test_equality(self, value): assert Left(value) == Left(value) assert Right(value) == Right(value)
def test_left_identity_law(self, value, f: Unary[Any, Either]): assert Right(value).and_then(f) == f(value)
def test_gather(self): assert gather([Right(v) for v in range(3)]) == Right((0, 1, 2))