Created
July 16, 2015 07:16
-
-
Save allending/6cdbc304568480190fd1 to your computer and use it in GitHub Desktop.
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
import Foundation | |
extension SequenceType { | |
func each(@noescape block: (element: Self.Generator.Element) -> Void) { | |
for item in self { | |
block(element: item) | |
} | |
} | |
func eachWithIndex(@noescape block: (Int, Self.Generator.Element) -> Void) { | |
for (index, element) in self.enumerate() { | |
block(index, element) | |
} | |
} | |
} | |
let arr = ["1 goat", 2, "3"] | |
arr.each { print($0) } | |
arr.eachWithIndex { print("index:\($0), value: \($1)") } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment