Created
July 11, 2016 18:05
-
-
Save dmyersturnbull/ebb686dc9f86cbb76013f1174026fb34 to your computer and use it in GitHub Desktop.
Efficient existential quantifier for a filter() predicate.
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
| from typing import Callable, Generic, TypeVar, Iterable | |
| T = TypeVar('T') | |
| def exists(keep_predicate: Callable[[T], bool], seq: Iterable[T]) -> bool: | |
| """Efficient existential quantifier for a filter() predicate. | |
| Returns true iff keep_predicate is true for one or more elements.""" | |
| for e in seq: | |
| if keep_predicate(e): return True # short-circuit | |
| return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment