Created
December 8, 2015 19:10
-
-
Save jshier/73e184c727b74c8f86f9 to your computer and use it in GitHub Desktop.
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
extension SequenceType { | |
@warn_unused_result | |
func firstElement(@noescape predicate: (Self.Generator.Element) throws -> Bool) rethrows -> Self.Generator.Element? { | |
for element in self { | |
if try predicate(element) { | |
return element | |
} | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Swift SequenceType extension to get the first element of a collection that matches the predicate closure passed in.