Skip to content

Instantly share code, notes, and snippets.

@jsuereth
Created February 13, 2012 16:50
Show Gist options
  • Save jsuereth/1818131 to your computer and use it in GitHub Desktop.
Save jsuereth/1818131 to your computer and use it in GitHub Desktop.
Simplified Iteratees using trait modules
// Note: "Context" is the Monad through which these classes are threaded. There also exists a type alias for the error channel between
// consumers and producers so that Consumers can be random-access. That code lives in the "randomaccess" universe for Iteratees, which is
// an extension of the sequential "nio" universe.
// Note: I don't have a ConsumerT, ProducerT, or StreamConverterT yet.
trait Consumer[I,O] {
/** Fold takes a function that matches the current state of this Consumer and produces a result. */
def fold[R](f: ConsumerState[I,O] => Context[R]): Context[R]
}
trait Producer[A] {
/** Feeds values from this producer into a consumer. */
def into[O](c: Consumer[A, O]): Consumer[A, O]
}
trait StreamConversion[I,I2] {
def apply[O](i: Consumer[I2,O]): Consumer[I, Consumer[I2, O]]
def convert[O](i: Consumer[I2, O])(implicit ev0: Empty[I]): Consumer[I, O] = apply(i).join
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment