\title{Classes for user-defined Producers and Consumers}


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


FunctionProducer(FUN, RESET, ..., state=NULL)
FunctionConsumer(FUN, RESET, ..., state=NULL)


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

  \item{RESET}{An optional function of one arugment (\sQuote{state}) to
    reset the stream to its original state. If missing, the stream
    cannot be reset.}

  \item{...}{Arguments passed to the \code{\linkS4class{Producer}}-class
    or \code{\linkS4class{Consumer}}-class constructors.}

  \item{state}{Any information, made available to \code{RESET}.}



  Use \code{FunctionProducer} or \code{FunctionConsumer} to construct
  instances of this class.



  See \code{\link{Producer}} and \code{\link{Consumer}} Methods.


\section{Internal Class Fields and Methods}{

  Internal fields of this class are are described with, e.g.,

  Internal methods of this class are described with
  \code{getRefClass("FunctionProducer")$methods()} and


\author{Nishant Gopalakrishnan \url{ngopalak@fhcrc.org}}


## 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)

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

neg10log10 <- FunctionConsumer(consumerFun)

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