Skip to content

Instantly share code, notes, and snippets.

@oliverbarreto
Created June 8, 2015 19:49
Show Gist options
  • Save oliverbarreto/b128a629829712012c13 to your computer and use it in GitHub Desktop.
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:
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