How to use the pfun.free.Done 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_free.py View on Github external
def test_inequality(self, first, second):
        assume(first != second)
        assert Done(first) != Done(second)
github suned / pfun / tests / test_free.py View on Github external
def test_sequence(self):
        assert sequence([Done(v) for v in range(3)]) == Done((0, 1, 2))
github suned / pfun / tests / test_free.py View on Github external
        assert filter_m(lambda v: Done(v % 2 == 0), range(3)) == Done((0, 2))
github suned / pfun / tests / test_free.py View on Github external
def test_composition_law(self, f, g, value):
        h = compose(f, g)
        assert Done(value).map(g).map(f) == Done(value).map(h)
github suned / pfun / tests / test_free.py View on Github external
def test_map_m(self):
        assert map_m(Done, range(3)) == Done((0, 1, 2))
github suned / pfun / pfun / free.py View on Github external
        return self.and_then(lambda v: Done(f(v)))
github suned / pfun / examples / free_kvstore.py View on Github external
    return More(Get(k, lambda v: Done(v)))
github suned / pfun / examples / free_kvstore.py View on Github external
def delete(k: str) -> KVStoreFree[None]:
    return More(Delete(k, Done(None)))
github suned / pfun / examples / free_kvstore.py View on Github external
def put(k: str, v: str) -> KVStoreFree[None]:
    return More(Put(k, v, Done(None)))
github suned / pfun / pfun / free.py View on Github external
:example:
    >>> from typing import Any
    >>> @with_effect
    ... def f() -> Frees[int, int, Any, Any]:
    ...     a = yield Done(2)
    ...     b = yield Done(2)
    ...     return a + b
    >>> f()
    Done(4)

    :param f: generator function to decorate
    :return: `f` decorated such that generated :class:`Free` \
        will be chained together with `and_then`
    """
    return with_effect_(Done, f)  # type: ignore