Created
July 20, 2015 19:20
-
-
Save ketzusaka/307c073449c506b340d3 to your computer and use it in GitHub Desktop.
First in Swift
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
| /** | |
| Find the first element in a sequence passing a test. | |
| :param: source Source sequence to iterate | |
| :param: includeElement Closure to evaluate elements with | |
| :return: First element in the sequence for which includeElement returns true, or nil if none found | |
| */ | |
| public func first<S: SequenceType>(source: S, includeElement: (S.Generator.Element) -> Bool) -> S.Generator.Element? { | |
| var filteredSource = lazy(source).filter(includeElement).generate() | |
| return filteredSource.next() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment