Exemple #1
0
def test_first_is_lazy():
    def once():
        yield Just(42)
        raise Exception

    assert first(once()) == Just(42)
Exemple #2
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)
Exemple #3
0
def test_first_default():
    assert first([Nothing, Nothing], default=Just(42)) == Just(42)
Exemple #4
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
Exemple #5
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