Esempio n. 1
0
    def test_match_function_constructor(self, Maybe):
        x = Maybe.Just(42)
        y = Maybe.Nothing

        func = Maybe.match_fn(
            just=lambda x: x * 2,
            nothing=lambda: 0,
        )
        assert func(x) == 84
        assert func(y) == 0
Esempio n. 2
0
    def test_match_fn_raises_error_on_non_exaustive_options(self, Maybe):
        with pytest.raises(ValueError):
            Maybe.match_fn(just=lambda x: x, )

        with pytest.raises(ValueError):
            Maybe.match_fn(
                just=lambda x: x,
                nothing=lambda: 0,
                other=lambda: 0,
            )

        with pytest.raises(ValueError):
            Maybe.match_fn(
                ok=lambda x: x,
                err=lambda: 0,
            )