Skip to content

Instantly share code, notes, and snippets.

@krzyzanowskim
Last active June 30, 2020 03:09
Show Gist options
  • Save krzyzanowskim/d3f2181081dda78e09d52c5b8b73f208 to your computer and use it in GitHub Desktop.
Save krzyzanowskim/d3f2181081dda78e09d52c5b8b73f208 to your computer and use it in GitHub Desktop.
anySatisfy
public extension Collection {
func anySatisfy(_ predicate: (Self.Element) throws -> Bool) rethrows -> Bool {
try reduce(false) {
try predicate($1) || $0
}
}
}
/*
[true, false].anySatisfy { $0 == false } // true
[true, true].anySatisfy { $0 == false } // false
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment