samer@10: function h=product_it(f,g) samer@10: % product_it- compose two iterators to run in parallel samer@10: % samer@10: % product_it:: samer@10: % iterator(A) ~'first iterator transformer and initial value', samer@10: % iterator(B) ~'second iterator transformer and initial value', samer@10: % -> iterator(cell {A,B}) ~'combined iterator'. samer@10: % samer@10: % The state transformer function returns [] to signal termination samer@10: % if EITHER of the sub-transformer functions returns []. samer@10: samer@10: ff=f{1}; gg=g{1}; samer@10: h={@prodit,{f{2},g{2}}}; samer@10: samer@10: function h=prodit(s) samer@10: s1=ff(s{1}); samer@10: s2=gg(s{2}); samer@10: if isempty(s1) || isempty(s2) samer@10: h=[]; samer@10: else samer@10: h={s1,s2}; samer@10: end samer@10: end samer@10: end samer@10: