Ejemplo 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])
Ejemplo n.º 2
0
def test_from_ok() -> None:
    assert Just(3) == Maybe.fromResult(Ok(3))
Ejemplo n.º 3
0
def test_from_nonempty_list() -> None:
    assert Just(2) == Maybe.fromList([2, 4, 6])
Ejemplo n.º 4
0
def test_from_empty_list() -> None:
    assert Nothing() == Maybe.fromList([])
Ejemplo n.º 5
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))
Ejemplo n.º 6
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))
Ejemplo n.º 7
0
def test_from_optional_none() -> None:
    assert Nothing() == Maybe.fromOptional(None)
Ejemplo n.º 8
0
def test_from_optional_value() -> None:
    assert Just(2) == Maybe.fromOptional(2)
Ejemplo n.º 9
0
def test_from_err() -> None:
    assert Nothing() == Maybe.fromResult(Err("oops"))