FunctionProducerConsumer-classes: Classes for user-defined Producers and Consumers

Description Usage Arguments Constructors Methods Internal Class Fields and Methods Author(s) See Also Examples

Description

The FunctionProducer and FunctionConsumer classes provide an easy way to quickly create Producer and Consumer instances from user-provided functions.

Usage

1
2

Arguments

FUN

User defined function to yield successive records in the stream. The FunctionProducer function must return an object of length 0 (e.g., logical(0)) when the stream is complete.

RESET

An optional function of one arugment (‘state’) to reset the stream to its original state. If missing, the stream cannot be reset.

...

Arguments passed to the Producer-class or Consumer-class constructors.

state

Any information, made available to RESET.

Constructors

Use FunctionProducer or FunctionConsumer to construct instances of this class.

Methods

See Producer and Consumer Methods.

Internal Class Fields and Methods

Internal fields of this class are are described with, e.g., getRefClass("FunctionProducer")$fields.

Internal methods of this class are described with getRefClass("FunctionProducer")$methods() and getRefClass("FunctionProducer")$help().

Author(s)

Nishant Gopalakrishnan ngopalak@fhcrc.org

See Also

Stream

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## A ProducerFunction
producerFun <- function() 
    ## produce the mean of 10 random uniform numbers
    ## stop when the mean is greater than 0.8
{
    x <- mean(runif(10))
    if (x > .8) numeric(0) else x
}
randomSampleMeans <- FunctionProducer(producerFun)
result <- sapply(randomSampleMeans, c)
length(result)
head(result)

## A FunctionConsumer:
consumerFun <- function(y)
    ## transform input by -10 log10
{
    -10 * log10(y)
}

neg10log10 <- FunctionConsumer(consumerFun)

strm <- Stream(randomSampleMeans, neg10log10)
result <- sapply(strm, c)
length(result)
head(result)

Streamer documentation built on Nov. 8, 2020, 5:53 p.m.