Last active
August 25, 2017 04:04
-
-
Save philsquared/63a0cc5817a6211fe91a12d9f76bd2ad to your computer and use it in GitHub Desktop.
countIf() in Swift
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
extension Sequence { | |
func countIf( predicate: (Self.Iterator.Element) -> Bool ) -> Int { | |
return reduce( 0 ) { predicate($1) ? $0+1 : $0 } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment