Ejemplo n.º 1
0
def sequence(monad_t, monad_list):
    """Evaluates each action in sequence from left to right and
    collects the results."""

    def helper(monad, acc):
        "Helper for sequence."
        return monad >= (lambda x: (acc >= (lambda xs: (monad_t.return_m(xs + [x])))))

    return func.foldr(helper, monad_t.return_m([]), list(reversed(monad_list)))
Ejemplo n.º 2
0
def sequence(monad_t, monad_list):
    """Evaluates each action in sequence from left to right and
    collects the results."""
    def helper(monad, acc):
        "Helper for sequence."
        return monad >= (lambda x: (acc >= (lambda xs:
                                            (monad_t.return_m(xs + [x])))))

    return func.foldr(helper, monad_t.return_m([]), list(reversed(monad_list)))
Ejemplo n.º 3
0
def sequence_(monad_t, monad_list):
    """Evaluates each action in sequence from
    left to right and dumps the results."""
    return func.foldr(monad_t.then, monad_t.return_m(func.Unit()), monad_list)
Ejemplo n.º 4
0
def msum(monad_t, monad_list):
    "Generalized concatenation."
    return func.foldr(monad_t.mplus(), monad_t.mzero(), monad_list)
Ejemplo n.º 5
0
def sequence_(monad_t, monad_list):
    """Evaluates each action in sequence from
    left to right and dumps the results."""
    return func.foldr(monad_t.then, monad_t.return_m(func.Unit()), monad_list)
Ejemplo n.º 6
0
def msum(monad_t, monad_list):
    "Generalized concatenation."
    return func.foldr(monad_t.mplus(), monad_t.mzero(), monad_list)