How to use the pfun.maybe.Just function in pfun

To help you get started, we’ve selected a few pfun examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github suned / pfun / tests / test_maybe.py View on Github external
def _test_just_inequality(self, value):
        assert Just(value) != Nothing()
github suned / pfun / tests / test_maybe.py View on Github external
def _test_nothing_inequality(self, first, second):
        assume(first != second)
        assert Just(first) != Just(second)
github suned / pfun / tests / test_maybe.py View on Github external
def test_composition_law(self, f: Unary, g: Unary, value):
        h = compose(f, g)
        assert Just(value).map(h) == Just(value).map(g).map(f)
        assert Nothing().map(h) == Nothing().map(g).map(f)
github suned / pfun / tests / test_maybe.py View on Github external
def _test_just_equality(self, value):
        assert Just(value) == Just(value)
github suned / pfun / tests / test_maybe.py View on Github external
def test_sequence(self):
        assert sequence([Just(v) for v in range(3)]) == Just((0, 1, 2))
github suned / pfun / tests / strategies.py View on Github external
def maybes(value_strategy=anything()):
    justs = builds(maybe.Just, value_strategy)
    nothings = just(maybe.Nothing())
    return one_of(justs, nothings)
github suned / pfun / pfun / maybe.py View on Github external
"""
    Map each element in ``iterable`` by applying ``f``,
    filter the results by the value returned by ``f``
    and combine from left to right.

    Example:
        >>> filter_m(lambda v: Just(v % 2 == 0), range(3))
        Just((0, 2))

    Args:
        f: Function to map ``iterable`` by
        iterable: Iterable to map by ``f``
    Return:
        `iterable` mapped and filtered by `f`
    """
    return cast(Maybe[Iterable[A]], filter_m_(Just, f, iterable))
github suned / pfun / pfun / dict.py View on Github external
Nothing()
            >> Dict({'key': 'value'}).get('key')
            Just('value')

        Args:
            key: the key to retrieve
            default: value to return if the key is not found
        Return:
            `Just` if key is found in dictionary
                 or default is given,
                 `Nothing` otherwise
        """
        v = self._d.get(key)
        if v is None:
            return Nothing()
        return Just(v)