<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 18, 2015, at 5:46 PM, T.J. Usiyan <<a href="mailto:griotspeak@gmail.com" class="">griotspeak@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">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. </div></div></blockquote><div><br class=""></div><div>Not sure what that means, I’m afraid.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class="">Small price to pay and all that. Thanks for the insight!</div></div></blockquote><div><br class=""></div>Glad to help.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_extra"><div class="gmail_quote">On Fri, Dec 18, 2015 at 8:19 PM, T.J. Usiyan <span dir="ltr" class=""><<a href="mailto:griotspeak@gmail.com" target="_blank" class="">griotspeak@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">That is… damned nice. I choose not to feel that bad about it… for reasons.<div class=""><br class=""></div><div class=""><br class=""></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Dec 18, 2015 at 8:04 PM, Dave Abrahams <span dir="ltr" class=""><<a href="mailto:dabrahams@apple.com" target="_blank" class="">dabrahams@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><span class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 18, 2015, at 4:35 AM, Al Skipp via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><blockquote type="cite" class=""><div class="">On 18 Dec 2015, at 00:19, T.J. Usiyan via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><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" class="">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" class="">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" class="">), 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" class=""><br class=""></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" class=""><font class=""><font face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size:12px;line-height:16px;white-space:pre-wrap" class="">`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 class=""><div class="">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 class=""></div></span><div class="">This is a much simpler cartesian product implementation:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""> seq1.flatMap { x in seq2.map { (x,$0) } }</font></div><div class=""><br class=""></div><div class="">or, if you want speed,</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class=""> seq1<b class="">.lazy</b>.flatMap { x in seq2<b class="">.lazy</b>.map { (x,$0) } }</font></div></div><div class=""><br class=""></div><div class="">HTH,</div><div class=""><br class=""></div><div class="">
-Dave<div class=""><br class=""></div><br class="">
</div>
<br class=""></div></blockquote></div><br class=""></div>
</div></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""><div class="">
-Dave<div class=""><br class=""></div><br class="Apple-interchange-newline">
</div>
<br class=""></body></html>