<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Here's what I ended up with. (<span style="font-family: Palatino-Roman;" class="">The use-case for this ended up being light-weight game tile placement, not image processing or anything.</span><span style="font-family: Palatino-Roman;" class="">&nbsp;)</span></div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);"><span class="" style="color: rgb(187, 44, 162);">func</span><span class="" style="color: rgb(0, 0, 0);">&nbsp;cartesianProduct&lt;S1:&nbsp;</span>SequenceType<span class="" style="color: rgb(0, 0, 0);">, S2:&nbsp;</span>SequenceType<span class="" style="color: rgb(0, 0, 0);">&gt;(s1:&nbsp;</span>S1<span class="" style="color: rgb(0, 0, 0);">,&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">_</span><span class="" style="color: rgb(0, 0, 0);">&nbsp;s2:&nbsp;</span>S2<span class="" style="color: rgb(0, 0, 0);">) -&gt;&nbsp;</span>AnySequence<span class="" style="color: rgb(0, 0, 0);">&lt;(</span>S1<span class="" style="color: rgb(0, 0, 0);">.</span>Generator<span class="" style="color: rgb(0, 0, 0);">.</span>Element<span class="" style="color: rgb(0, 0, 0);">,&nbsp;</span>S2<span class="" style="color: rgb(0, 0, 0);">.</span>Generator<span class="" style="color: rgb(0, 0, 0);">.</span>Element<span class="" style="color: rgb(0, 0, 0);">)&gt; {</span></div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">let</span>&nbsp;items = s1.<span class="" style="color: rgb(112, 61, 170);">lazy</span>.<span class="" style="color: rgb(61, 29, 129);">flatMap</span>({</div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; item1&nbsp;<span class="" style="color: rgb(187, 44, 162);">in</span>&nbsp;s2.<span class="" style="color: rgb(112, 61, 170);">lazy</span>.<span class="" style="color: rgb(61, 29, 129);">map</span>({</div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; item2&nbsp;<span class="" style="color: rgb(187, 44, 162);">in</span>&nbsp;(item1, item2)})})</div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">return</span>&nbsp;<span class="" style="color: rgb(112, 61, 170);">AnySequence</span>&nbsp;{items.<span class="" style="color: rgb(61, 29, 129);">generate</span>()}</div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">}</div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; min-height: 21px;"><br class=""></div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);"><span class="" style="color: rgb(187, 44, 162);">func</span><span class="" style="color: rgb(0, 0, 0);">&nbsp;cartesianProduct&lt;S1:&nbsp;</span>SequenceType<span class="" style="color: rgb(0, 0, 0);">, S2:&nbsp;</span>SequenceType<span class="" style="color: rgb(0, 0, 0);">, S3:&nbsp;</span>SequenceType<span class="" style="color: rgb(0, 0, 0);">&gt;(s1:&nbsp;</span>S1<span class="" style="color: rgb(0, 0, 0);">,&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">_</span><span class="" style="color: rgb(0, 0, 0);">&nbsp;s2:&nbsp;</span>S2<span class="" style="color: rgb(0, 0, 0);">,&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">_</span><span class="" style="color: rgb(0, 0, 0);">&nbsp;s3:&nbsp;</span>S3<span class="" style="color: rgb(0, 0, 0);">) -&gt;&nbsp;</span>AnySequence<span class="" style="color: rgb(0, 0, 0);">&lt;(</span>S1<span class="" style="color: rgb(0, 0, 0);">.</span>Generator<span class="" style="color: rgb(0, 0, 0);">.</span>Element<span class="" style="color: rgb(0, 0, 0);">,&nbsp;</span>S2<span class="" style="color: rgb(0, 0, 0);">.</span>Generator<span class="" style="color: rgb(0, 0, 0);">.</span>Element<span class="" style="color: rgb(0, 0, 0);">,&nbsp;</span>S3<span class="" style="color: rgb(0, 0, 0);">.</span>Generator<span class="" style="color: rgb(0, 0, 0);">.</span>Element<span class="" style="color: rgb(0, 0, 0);">)&gt; {</span></div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">let</span>&nbsp;items = s1.<span class="" style="color: rgb(112, 61, 170);">lazy</span>.<span class="" style="color: rgb(61, 29, 129);">flatMap</span>({</div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; item1&nbsp;<span class="" style="color: rgb(187, 44, 162);">in</span>&nbsp;s2.<span class="" style="color: rgb(112, 61, 170);">lazy</span>.<span class="" style="color: rgb(61, 29, 129);">flatMap</span>({</div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; item2&nbsp;<span class="" style="color: rgb(187, 44, 162);">in</span>&nbsp;s3.<span class="" style="color: rgb(112, 61, 170);">lazy</span>.<span class="" style="color: rgb(61, 29, 129);">map</span>({</div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; item3&nbsp;<span class="" style="color: rgb(187, 44, 162);">in</span>&nbsp;(item1, item2, item3)})})})</div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">return</span>&nbsp;<span class="" style="color: rgb(112, 61, 170);">AnySequence</span>&nbsp;{items.<span class="" style="color: rgb(61, 29, 129);">generate</span>()}</div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;">}</div></div><br class=""><div><span style="font-family: Palatino-Roman;" class="">I initially suggested to the person I was helping:</span></div><div><span style="font-family: Palatino-Roman;" class=""><br class=""></span></div><div><font face="Courier" class="">for y in (...) {</font></div><div><font face="Courier" class="">&nbsp; &nbsp; for x in (...) {</font></div><div><font face="Courier" class="">&nbsp; &nbsp; &nbsp; ...</font></div><div><font face="Courier" class="">&nbsp; &nbsp; }</font></div><div><font face="Courier" class="">}</font></div><div><br class=""></div><div><span style="font-family: Palatino-Roman;" class="">But I'm glad I got to explore several alternative approaches. Thanks all.&nbsp;</span>A few extra notes, to summarize everything into a single post:</div><div><br class=""></div><div>Joe writes: "<span style="font-family: Palatino-Roman;" class=""><i class="">[AnySeq/Gen] aren't on the way out. We'd like to migrate them with first-class language support for protocol types with associated type constraints, but we wouldn't eliminate the functionality.</i>"</span></div><div><br class=""></div><div>Dmitri adds: "<span style="font-family: Palatino-Roman;" class=""><i class="">You can use AnySequence and AnyGenerator, but they come at a cost of dynamic dispatch for every call.&nbsp; In this case, if you want this component to be suitable for performance-critical code, I would suggest to avoid them for now.</i>"</span></div><div><span style="font-family: Palatino-Roman;" class=""><br class=""></span></div><div><br class=""></div><div><span style="font-family: Palatino-Roman;" class="">-- E</span></div><div><br class=""><blockquote type="cite" class=""><div class="">On Dec 18, 2015, at 11:08 PM, Rob Mayoff via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">1. Can anyone recommended a better name than Cartesian? 2D doesn't work for the compiler and I'm looking for something that doesn't seem "floating-point"-y</div></div></blockquote><div class=""><br class=""></div><div class="">"AllPairs" seems self-explanatory.</div><div class=""><br class=""></div><div class="">"CrossJoin" should be intuitive to anyone familiar with relational databases.</div><div class=""><br class=""></div><div class="">"product" sounds like it might be multiplying elements with each other.</div><div class=""><br class=""></div></div></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=r5jpKsi6nat7oa43lpCLi5GRGm2utDkbDscuFklXZ2dkL4kky3qjs5mSyfoochJq-2FB8BcpLHoRGPFWmfzp-2BpUhz0j18a4w0VVo8N-2FXpSSFLQABZkB88Gkiz2Un0vb7SVqtociJC7-2F50WScaSPIFzWmzUobmIGJqwBhbL8T5z8IBBEv2pNfMi-2B-2FyMbOkKLQIlvob7Vu4QlKT6fkGB-2FbxApg-2Bf3SI8a8wS3T9MGs3ra8Y-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></body></html>