1:3 %>% reduce(`+`)
1:10 %>% reduce(`*`)
5 %>%
replicate(sample(10, 5), simplify = FALSE) %>%
reduce(intersect)
x <- list(c(0, 1), c(2, 3), c(4, 5))
x %>% reduce(c)
x %>% reduce_right(c)
# Equivalent to:
x %>% rev() %>% reduce(c)
# Use init when you want reduce to return a consistent type when
# given an empty lists
list() %>% reduce(`+`)
list() %>% reduce(`+`, .init = 0)
Run the code above in your browser using DataLab