<div dir="ltr">Updated the library with that. The only downside that I can see is that flattening, as I had always planned but finally bothered to do, has no way to tell if the left tuple was the produce of a previous cartesian product operation. Small price to pay and all that. Thanks for the insight!</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 18, 2015 at 8:19 PM, T.J. Usiyan <span dir="ltr"><<a href="mailto:griotspeak@gmail.com" target="_blank">griotspeak@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">That is… damned nice. I choose not to feel that bad about it… for reasons.<div><br></div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 18, 2015 at 8:04 PM, Dave Abrahams <span dir="ltr"><<a href="mailto:dabrahams@apple.com" target="_blank">dabrahams@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span><br><div><blockquote type="cite"><div>On Dec 18, 2015, at 4:35 AM, Al Skipp via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On 18 Dec 2015, at 00:19, T.J. Usiyan via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">With a Cartesian Product type [like this](</span><a href="https://github.com/griotspeak/CartesianProduct" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://github.com/griotspeak/CartesianProduct</a><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">), the for-in-where syntax actually gets us to list comprehensions. I'll admit that I might not have implemented the best Cartesian Product type possible, but it should illustrate that we have what we need.</span><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font><font face="Consolas, Liberation Mono, Menlo, Courier, monospace"><span style="font-size:12px;line-height:16px;white-space:pre-wrap">`for case … in cartProd(cartProd(seq1, seq2), seq3) // An operator for cartProd would make it more pleasing to read.`</span></font></font></div></div></blockquote></div><br><div>That’s impressive work, but it strikes me as quite a difficult undertaking to get there. (Is it just me, or are generators and sequences the most scary part of Swift?) Also, is it possible to get it working as an expression, or is it restricted to a ‘for’ statement? If it can only be performed as a ‘for’ statement it will still need an external mutable var to be updated outside of the loop. It’s fine if you want to just do side-effecty things, like print the elements, but I’d consider the ability to return a value to be more important.</div></div></div></blockquote><br></div></span><div>This is a much simpler cartesian product implementation:</div><div><br></div><div><font face="Menlo"> seq1.flatMap { x in seq2.map { (x,$0) } }</font></div><div><br></div><div>or, if you want speed,</div><div><br></div><div><div><font face="Menlo"> seq1<b>.lazy</b>.flatMap { x in seq2<b>.lazy</b>.map { (x,$0) } }</font></div></div><div><br></div><div>HTH,</div><div><br></div><div>
-Dave<div><br></div><br>
</div>
<br></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>