Exemplo n.º 1
0
def test_first_is_lazy():
    def once():
        yield Just(42)
        raise Exception

    assert first(once()) == Just(42)
Exemplo n.º 2
0
def test_first_predicate():
    assert first([False, 0, 2, 1], predicate=bool) == Just(2)
    assert first([False, 0, ''], predicate=bool) == Nothing
    assert first(range(100), predicate=lambda x: x > 50) == Just(51)
    assert first(range(100), predicate=lambda x: x > 100) == Nothing
Exemplo n.º 3
0
def test_first_wrap_just_only_if_not_already():
    assert first([False, True], predicate=bool) == Just(True)
    assert first([False, Just(True)], bool) != Just(Just(True))
    assert first([False, Just(True)], bool) == Just(True)
Exemplo n.º 4
0
def test_first():
    assert first([Nothing, Just(42)]) == Just(42)
    assert first([Just(42), Just(43)]) == Just(42)
    assert first([Nothing, Nothing]) == Nothing
    assert first([]) == Nothing
Exemplo n.º 5
0
def test_first_default():
    assert first([Nothing, Nothing], default=Just(42)) == Just(42)
Exemplo n.º 6
0
def test_first_is_lazy():
    def once():
        yield Just(42)
        raise Exception

    assert first(once()) == Just(42)
Exemplo n.º 7
0
def test_first_wrap_just_only_if_not_already():
    assert first([False, True], predicate=bool) == Just(True)
    assert first([False, Just(True)], bool) != Just(Just(True))
    assert first([False, Just(True)], bool) == Just(True)
Exemplo n.º 8
0
def test_first_predicate():
    assert first([False, 0, 2, 1], predicate=bool) == Just(2)
    assert first([False, 0, ''], predicate=bool) == Nothing
    assert first(range(100), predicate=lambda x: x > 50) == Just(51)
    assert first(range(100), predicate=lambda x: x > 100) == Nothing
Exemplo n.º 9
0
def test_first_default():
    assert first([Nothing, Nothing], default=Just(42)) == Just(42)
Exemplo n.º 10
0
def test_first():
    assert first([Nothing, Just(42)]) == Just(42)
    assert first([Just(42), Just(43)]) == Just(42)
    assert first([Nothing, Nothing]) == Nothing
    assert first([]) == Nothing