product-find ( ... sequences quot: ( ... seq -- ... ? ) -- ... sequence )
Product sequences

Prev:product-each ( ... sequences quot: ( ... seq -- ... ) -- ... )


Vocabulary
sequences.product

Inputs
sequencesa sequence
quota quotation with stack effect ( ... seq -- ... ? )


Outputs
sequencea sequence


Word description
Calls quot for every element of the cartesian product of sequences, returning the first sequence where the quotation returns a true value.

Notes
[ ... ] product-find is equivalent to, but more efficient than, <product-sequence> [ ... ] find nip.

See also
product-map, product-each

Definition


:: product-find
( ... sequences quot: ( ... seq -- ... ? ) -- ... sequence )
sequences start-product-iter :> ( ns lengths ) lengths
[ 0 = ] any?
[ f ] [
f
[ ns lengths end-product-iter? over or ] [
drop ns sequences product-nths quot keep and
ns lengths product-iter
] until
] if ; inline