Created
October 21, 2016 02:13
-
-
Save JJC1138/b2b9d95d299337e15e39d674cea85aa9 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
fileprivate extension Array { | |
func filterIntoTrueAndFalse(_ shouldBeIncludedInFirstResult: (Element) throws -> Bool) rethrows -> ([Element], [Element]) { | |
var trueResults = [Element]() | |
var falseResults = [Element]() | |
for i in self { | |
if try shouldBeIncludedInFirstResult(i) { | |
trueResults.append(i) | |
} else { | |
falseResults.append(i) | |
} | |
} | |
return (trueResults, falseResults) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just bounced in here by chance (from SO), and couldn't help writing another (probably slightly less performant and surely more
try
messy) alternative to the above, for the fun of it :)