 
 : 2each ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... ) -- ... )
     (2each) each-integer ; inline
+
+: 2each-from ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... ) i -- ... )
+    [ (2each) ] dip -rot (each-integer) ; inline
 
 : 2reduce ( ... seq1 seq2 identity quot: ( ... prev elt1 elt2 -- ... next ) -- ... result )
     [ -rot ] dip 2each ; inline


: cartesian-product ( seq1 seq2 -- newseq )
    [ { } 2sequence ] cartesian-map ;

: each-from ( ... seq quot: ( ... x -- ... ) i -- ... )
    -rot (each) (each-integer) ; inline

<PRIVATE



: map-reduce ( ..a seq map-quot: ( ..a elt -- ..b intermediate ) reduce-quot: ( ..b prev intermediate -- ..a next ) -- ..a result )
    [ [ dup first ] dip [ call ] keep ] dip compose
    swapd 1 each-from ; inline

: 2map-reduce ( ..a seq1 seq2 map-quot: ( ..a elt1 elt2 -- ..b intermediate ) reduce-quot: ( ..b prev intermediate -- ..a next ) -- ..a result )
    [ [ 2dup [ first ] bi@ ] dip [ call ] keep ] dip compose
    [ -rot ] dip 1 2each-from ; inline

<PRIVATE

