async_filter keep the elements for which .p is true. (Tested via isTRUE(). async_reject is the opposite, it drops them.

async_filter(.x, .p, ...)

async_reject(.x, .p, ...)

Arguments

.x

A list or atomic vector.

.p

An asynchronous predicate function.

...

Additional arguments to the predicate function.

Value

A deferred value for the result.

See also

Other async iterators: async_detect(), async_every(), async_map()

Examples

httpbin <- webfakes::new_app_process(
  webfakes::httpbin_app(),
  opts = webfakes::server_opts(num_threads = 3)
)
## Filter out non-working URLs
afun <- async(function(urls) {
  test_url <- async_sequence(
     http_head, function(x) identical(x$status_code, 200L))
  async_filter(urls, test_url)
})
urls <- c(httpbin$url("/get"),
          httpbin$url("/status/404"))
synchronise(afun(urls))
#> [1] "http://127.0.0.1:39743/get"