Created
July 20, 2014 10:07
-
-
Save ishikawa/bd4347ebecf0c254debd to your computer and use it in GitHub Desktop.
Swift find function which takes predicate closure
This file contains hidden or 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 | |
func find<C : Collection>(source: C, includeElement: (C.GeneratorType.Element) -> Bool) -> C.IndexType? { | |
for i in indices(source) { | |
if includeElement(source[i]) { | |
return i; | |
} | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// Updated for Swift 1.2