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:
Is this the way to write a schedule fold in noodles?
In the previous code snippet if fun is an schedule function, noodles will complain about unpacking a PromiseObject. How can I overcome this issues?
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:
The questions are:
noodles
?fun
is an schedule function, noodles will complain about unpacking aPromiseObject
. How can I overcome this issues?