Esempio n. 1
0
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])
Esempio n. 2
0
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))
Esempio n. 3
0
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))