Created
June 8, 2015 19:49
-
-
Save oliverbarreto/b128a629829712012c13 to your computer and use it in GitHub Desktop.
You can use enumerate to convert a sequence (Array, String, etc.) to a sequence of tuples with the index and element paired together. That is:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let numbers = [7, 8, 9, 10] | |
let indexAndNum: [String] = map(enumerate(numbers)) { (index, element) in | |
return "\(index): \(element)" | |
} | |
println(indexAndNum) | |
// [0: 7, 1: 8, 2: 9, 3: 10] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment