\title{Class defining methods for all Producers}


  A virtual class representing components that can read data from
  connections, and yield records to the user or a \code{Consumer}
  instance. A \code{Producer} represents a source of data, responsible
  for parsing a file or other data source into records to be passed to
  \code{Consumer} classes. \code{Producer} and \code{Consumer} instances
  are associated with each other through the \code{\link{Stream}}


\S4method{lapply}{Producer}(X, FUN, ...)

\S4method{sapply}{Producer}(X, FUN, ..., simplify=TRUE, USE.NAMES=TRUE)


  \item{X}{An instance of class \code{Producer}}

  \item{FUN}{A function to be applied to each successful \code{yield()}
    of \code{X}.}

  \item{...}{Additional arguments to \code{FUN}.}

  \item{simplify}{See \code{?base::sapply}.}

  \item{USE.NAMES}{See \code{?base::sapply} but note that names do not
    usually make sense for instances of class \code{Producer}.}



  Methods defined on this class include:


    \item{Stream}{Construct a stream from one \code{Producer} and one or
      more \code{Consumer}. See \code{?Stream}.}

    \item{yield}{Yield a single result (e.g., \code{data.frame}) from
      the Producer.}

    \item{reset}{Reset, if possible, the Producer.}

    \item{lapply, sapply}{Apply \code{FUN} to each result applied to
      \code{yield()}, simplifying (using \code{simplify2array}) if
      possible for \code{sapply}. Partial results on error can be
      recovered using \code{\link{tryCatch}}, as illustrated
      below. Infinite producers will of course exhaust memory.}


\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("Producer")$methods()} and


\author{Martin Morgan \url{mtmorgan@fhcrc.org}}


  \code{\link{Streamer-package}}, \code{\linkS4class{Consumer}-class},


showMethods(class="Producer", where="package:Streamer")

sapply(Seq(to=47, yieldSize=7), function(elt) {
    c(n = length(elt), xbar = mean(elt))

## recover partial results
fun = function(i) if (i == 5) stop("oops, i == 5") else i
res <- tryCatch(sapply(Seq(to=10), fun), error=function(err) {
            "\n  only partial results available")