<div dir="ltr">re: cross (nod to Dave Abrahams for the clean implementation)<div><br><div>/// 'Cartesian product' of two sequences<br>public func cartesianProduct<Left: Sequence, Right: Sequence>(lhs:Left, rhs:Right) -> [(Left.Iterator.Element, Right.Iterator.Element)] {<br> return lhs.flatMap { x in rhs.map { (x, $0) } }<br><br>}<div class="gmail_extra"><div class="gmail_quote">On Sun, Jul 17, 2016 at 11:54 AM, Nevin Brackett-Rozinsky via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</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">I think this use-case is too narrow for dedicated syntax in the standard library.<div><br></div><div>However, it should be simple enough for you to write your own function, let’s call it `unpack`, which produces a sequence that does what you want.</div><div><br></div><div>While you’re at it you could also try writing a `cross` function that takes two collections and produces all tuples of their elements, perhaps using something like .lazy.map.zip internally, if you need that functionality.<div><div><br></div><div>One great aspect of Swift is that it makes implementing things like this yourself readily achievable. Plus, once we get constrained extensions (extension Collection where Element: Collection) you should be able to do it that way too.</div><div><br></div><div>Alternatively, you might consider whether your data structure itself is ideal or if you’d be better off flattening everything into, say, a single dictionary that takes a compound key.</div><div><br></div><div>Nevin</div><div><br></div><div><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Sun, Jul 17, 2016 at 6:05 AM, Maxim Bogdanov via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hello, community.<br><br>As I understood from documentation the only way to iterate multidimensional array or a dictionary (with for loop) is this:<br><br><div>let multidimensionalDictionary = ["a":["b": "c"], "b":["c": "d"], "c": ["d": "e"]]</div><div>for (key, value) in multidimensionalDictionary {<br></div><div> for (nestedKey, nestedValue) in value {</div><div> print("\(key) -> \(nestedKey) -> \(nestedValue)")</div><div> }</div><div>}</div><div><br></div><div>What do you think about this syntax?<br><div>for (key, nestedKey, nestedValue) in multidimensionalDictionary {</div><div> print("\(key) -> \(nestedKey) -> \(nestedValue)")</div><div>}<br><br><br>--<br>I'm new to mailing list feature. If I do something wrong please let me know about it.<br><br>Best regards,<br>Maxim</div></div></div>
<br></div></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div></div></div>