# define a predicate function that tests whether the next element starts
# with an 'a'
starts_with_a <- function(x) grepl("^a", x)
# Use it in the satisfy parser
satisfy(starts_with_a)(c("abc", "def")) # success
satisfy(starts_with_a)(c("bca", "def")) # failure
# Using an anonymous function
satisfy(function(x) {
as.numeric(x) > 10
})("15") # success
Run the code above in your browser using DataLab