Created
February 13, 2012 16:50
-
-
Save jsuereth/1818131 to your computer and use it in GitHub Desktop.
Simplified Iteratees using trait modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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