We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameterise detect() with a predicate:
detect()
detect <- function(.x, .f, ..., .right = FALSE, .p = is_true) { for (i in index(.x, .right)) { if (.p(.f(.x[[i]], ...))) { return(.x[[i]]) } } NULL }
Useful for detecting non-null values for instance.
The text was updated successfully, but these errors were encountered:
Along with something like:
detect_value <- function(.x, .f, .p, ..., .right = FALSE) { for (i in index(.x, .right)) { value <- .f(.x[[i]], ...) if (.p(value)) { return(value) } } NULL } detect_value(x, some_fn, negate(is_null))
Sorry, something went wrong.
Or should we test with is_trueish() instead?
is_trueish()
is_trueish <- function(x) { if (is_true(x)) { return(TRUE) } if (is_integerish(x, n = 1L, finite = TRUE)) { return(x != 0) } FALSE }
Then we can use it with e.g. anyDuplicated()
anyDuplicated()
detect(list(1:3, 4:6, c(7L, 8L, 7L)), anyDuplicated) #> [1] 7 8 7
Or should we keep is_true() by default, parameterise .p, and add is_trueish() to rlang?
is_true()
.p
Would get in the way of #470, and can be solved by wrapping .f with .p manually.
.f
No branches or pull requests
Parameterise
detect()
with a predicate:Useful for detecting non-null values for instance.
The text was updated successfully, but these errors were encountered: