Implement some() and every() helpers#716
Merged
Merged
Conversation
These are more efficient than `any`/`all` plus `vapply()` because they can early exit. Benchmarking confirms that they are faster even in the worst case scenario (`TRUE`/`FALSE` at last entry). ```R x <- as.list(1:10) bench::mark( # some() early-exits on first TRUE; any(vlapply) computes all some_early = some(x, \(v) v > 0), any_vlapply = any(vlapply(x, \(v) v > 0)), # worst case: no early exit possible every_full = every(x, \(v) v > 0), all_vlapply = all(vlapply(x, \(v) v > 0)), check = FALSE )[1:4] #> expression min median `itr/sec` #> <bch:expr> <bch:tm> <bch:tm> <dbl> #> 1 some_early 410.01ns 574.04ns 1157952. #> 2 any_vlapply 2.38µs 2.91µs 313534. #> 3 every_full 1.31µs 1.64µs 563264. #> 4 all_vlapply 2.34µs 2.91µs 330469. ```
t-kalinowski
approved these changes
Jun 24, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These are more efficient than
any/allplusvapply()because they can early exit. Benchmarking confirms that they are faster even in the worst case scenario (TRUE/FALSEat last entry).