How to use the pfun.trampoline.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_trampoline.py View on Github external
def test_stack_safety(self):
        with recursion_limit(100):
            sequence([Done(v) for v in range(500)]).run()
github suned / pfun / tests / test_trampoline.py View on Github external
def test_sequence(self):
        assert sequence([Done(v) for v in range(3)]).run() == (0, 1, 2)
github suned / pfun / pfun / io.py View on Github external
def run() -> Trampoline[None]:
        with open(path, mode + 'b') as f:
            f.write(content)
        return Done(None)
github suned / pfun / pfun / trampoline.py View on Github external
def run(self) -> A:
        """
        Interpret a structure of trampolines to produce a result

        Return:
            result of intepreting this structure of \
            trampolines
        """
        trampoline = self
        while not trampoline._is_done:
            trampoline = trampoline._resume()

        return cast(Done[A], trampoline).a
github suned / pfun / pfun / trampoline.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: Done(v % 2 == 0), range(3)).run()
        (0, 2)

    Args:
        f: Function to map ``iterable`` by
        iterable: Iterable to map by ``f``
    Return:
        `iterable` mapped and filtered by `f`
    """
    return cast(Trampoline[Iterable[A]], filter_m_(Done, f, iterable))
github suned / pfun / pfun / state.py View on Github external
            and_then(lambda tu: Done((f(tu[0]), tu[1])))
        )
github suned / pfun / pfun / trampoline.py View on Github external
        return self.and_then(lambda a: Done(f(a)))
github suned / pfun / pfun / reader.py View on Github external
    return Reader(lambda _: Done(v))
github suned / pfun / pfun / trampoline.py View on Github external
def sequence(iterable: Iterable[Trampoline[A]]) -> Trampoline[Iterable[A]]:
    """
    Evaluate each `Trampoline` in `iterable` from left to right
    and collect the results

    Example:
        >>> sequence([Done(v) for v in range(3)]).run()
        (0, 1, 2)

    Args:
        iterable: The iterable to collect results from
    Return:
        ``Trampoline`` of collected results
    """
    return cast(Trampoline[Iterable[A]], sequence_(Done, iterable))