 
 :: product-map-as ( ... sequences quot: ( ... seq -- ... value ) exemplar -- ... sequence )
     0 :> i!
-    sequences [ length ] [ * ] map-reduce exemplar
+    sequences product-length exemplar
     [| result |
-        sequences [ quot call i result set-nth i 1 + i! ] product-each
+        sequences [ quot call i result set-nth-unsafe i 1 + i! ] product-each
         result
     ] new-like ; inline
 


:: (carry-n) ( ns lengths i -- )
    ns length i 1 + = [
        i ns nth i lengths nth = [
            0 i ns set-nth
            i 1 + ns [ 1 + ] change-nth
            ns lengths i 1 + (carry-n)
        ] when
    ] unless ;

: carry-ns ( ns lengths -- )
    0 (carry-n) ;

: product-iter ( ns lengths -- )
    [ 0 over [ 1 + ] change-nth ] dip carry-ns ;

: start-product-iter ( sequences -- ns lengths )
    [ length 0 <array> ] [ [ length ] map ] bi ;

: end-product-iter? ( ns lengths -- ? )
    [ last ] same? ;

PRIVATE>



:: product-map>assoc ( ... sequences quot: ( ... seq -- ... key value ) exemplar -- ... assoc )
    0 :> i!
    sequences product-length { }
    [| result |
        sequences [ quot call 2array i result set-nth-unsafe i 1 + i! ] product-each
        result
    ] new-like exemplar assoc-like ; inline
