Description Usage Arguments Methods Internal Class Fields and Methods Author(s) See Also Examples
A Consumer
-class to reduce N successive records
into a single yield.
1 | Reducer(FUN, init, ..., yieldNth = NA_integer_)
|
FUN |
A function of two arguments, where the first argument is
the result of the previous reduction (or |
init |
An optional initial value to initiate the reduction. When
present, |
... |
Additional arguments, passed to the |
yieldNth |
A positive integer indicating how many upstream yields
are combined before the Reducer yields. A value of
|
See Consumer
Methods.
Internal fields of this class are are described with, e.g.,
getRefClass("Reducer")$fields
.
Internal methods of this class are described with
getRefClass("Reducer")$methods()
and
getRefClass("Reducer")$help()
.
Martin Morgan mtmorgan@fhcrc.org
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | s <- Stream(Seq(to=10), Reducer("+"))
yield(s) ## sum(1:10), i.e., Reduce over the entire stream
s <- Stream(Seq(to=10), Reducer("+", yieldNth=5))
yield(s) ## sum(1:5)
yield(s) ## sum(6:10)
s <- Stream(Seq(to=10), Reducer("+", init=10, yieldNth=5))
sapply(s, c) ## 10 + c(sum(1:5), sum(6:10))
if (.Platform$OS.type != "windows") {
s <- Stream(Seq(to=10),
Team(function(i) { Sys.sleep(1); i },
param=MulticoreParam(10L)),
Reducer("+"))
system.time(y <- yield(s))
y
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.