I would like to know how to write a python function that can smooth out a generator that gives other generators or iteables (which can also lead to other generators / iterators ... possibly endlessly).
Here is an example:
gen(gen(1,2,3), gen(4,5,6), [7,8,9], [gen(10,11,12), gen(13,14,15)])
note: gen - means a generator object, the contents between parentheses after gen are the data that will generate gen yield.
Expected result after smoothing: gen(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
The flatten function must also return a generator! (since otherwise the previous use of generators would be pointless).
Just note that I'm using python 3.
Thanks!
Joshuaboshi
source share