NLeSC / noodles

Computational workflow engine, making distributed computing in Python easy!
http://nlesc.github.io/noodles
Apache License 2.0
21 stars 7 forks source link

schedule Fold #54

Open felipeZ opened 7 years ago

felipeZ commented 7 years ago

I have found myself trying to run a set of schedule functions in a similar way that the reduce function from the functools module. Something similar to a Haskell fold.

The idea is to perform a first computation using an initial state and the first element of a list. Then, based on the resulting state carry out the second computation and so on. In python code, something like:

from typing import (Any, Callable, List)
from noodles import  schedule

@schedule
def schedule_fold(
        fun: Callable, acc: Any, xs: List, *args, **kwargs) -> Any:
    """
    Schedule a Fold function
    """
    rs = []
    for x in xs:
        r, acc = fun(acc,  x, *args, **kwargs)
        rs.append(r)

    return rs

The questions are: