Reduce binary predicate over a list
reduce_predicate.RdThis function applies a binary predicate function .f over a list .l,
checking if the result is TRUE for any or all ordered pairs within .l.
accumulate_predicate() is similar, but returns a logical vector of the
accumulated results of the tests.
Arguments
- .l
[
list()] A list of objects to compare.- .f
[
function()] A binary predicate function, that uses their first two arguments for the operation, and returns a singleTRUEorFALSE.- ...
Additional arguments passed to
.f.- .op
[
"or"|"and"] Whether to check if the predicate isTRUEfor any or any or all ordered pairs within.l.
Value
[
TRUE|FALSE|NA] Forreduce_predicate(): the scalar reduced result.[
logical(length(.l) - 1)] Foraccumulate_predicate(): the accumulated results.
Examples
reduce_predicate(list(1L, 1.0, 3), `==`, .op = "or") #> TRUE
#> [1] TRUE
reduce_predicate(list(1L, 1.0, 3), `==`, .op = "and") #> FALSE
#> [1] FALSE
accumulate_predicate(list(1L, 1.0, 3), `==`, .op = "and") #> c(TRUE, FALSE)
#> [1] TRUE FALSE
accumulate_predicate(list(1L, 1.0, 3), identical, .op = "and") #> c(FALSE, FALSE)
#> [1] FALSE FALSE