 : interleave ( ... seq between quot: ( ... elt -- ... ) -- ... )
     pick empty? [ 3drop ] [
         [ [ drop first-unsafe ] dip call ]
-        [ [ bi* ] 2curry [ 1 ] 2dip (each) (each-integer) ]
+        [ [ bi* ] 2curry 1 each-from ]
         3bi
     ] if ; inline
 


: 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 ] 2dip (each) (each-integer) ; 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 ] 3dip (2each) (each-integer) ; inline

<PRIVATE



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

<PRIVATE

