by
8,516 33

How do you map over the values of Zip2 in Swift?

foo has the type ZipGenerator2<IndexingGenerator<Array<Int>>, IndexingGenerator<Array<String>>>?.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/72378/How-do-you-map-over-the-values-of-Zip2-i?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
The following will get you an array from the return value of Zip2: var myZip = Zip2([1, 2, 3], ["a", "b", "c"]).generate() var myZipArray: Array<(Int, String)> = [] while let elem = myZip.next() { myZipArray += elem } println(myZipArray) // [(1, a), (2, b), (3, c)] -- UPDATE: EVEN BETTER! -- let myZip = Zip2([1, 2, 3], ["a", "b", "c"]) let myZipArray = Array(myZip) println(myZipArray) // [(1, a), (2, b), (3, c)] -- now for fun -- I'm going to guess that we can init a new Array with anything that responds to generate() ? println(Array("abcde")) // [a, b, c, d, e]
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus