def test_types() -> None: m: Maybe[int] = Maybe.pure(1) map: Maybe[int] = m.map(lambda x: x) map_operator: Maybe[int] = m * (lambda x: x) bind: Maybe[int] = m.bind(lambda x: Maybe.pure(x)) bind_operator: Maybe[int] = m >> (lambda x: Maybe.pure(x)) apply: Maybe[int] = m.apply(Maybe.pure(lambda x: x)) apply_operator: Maybe[int] = Maybe.pure(lambda x: x) & m sequence: Maybe[List[int]] = Maybe.sequence([m])
def test_apply_just_to_nothing() -> None: m: Maybe[int] = Nothing() increment: Callable[[int], int] = lambda x: x + 1 assert Nothing() == m.apply(Maybe.pure(increment))
def test_apply_just_to_just() -> None: m: Maybe[int] = Just(5) increment: Callable[[int], int] = lambda x: x + 1 assert Just(6) == m.apply(Maybe.pure(increment))