Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // *** Iterators / Iteratees *** //
- // Mutable variant:
- trait Iterator[E] {
- def next: E
- def hasNext: Boolean
- }
- // Immutable variant:
- trait Iterator[E] {
- def next: Option[(E, Iterator[E])]
- }
- // Free variant:
- case class Get[E, A](f: Option[E] => A)
- trait Iteratee[E, A] = Free[({type λ[x] = Get[E, x]})#λ, A]
- // Why would you ever use Iteratee when you have State with Iterator?
- // *** Consumers / Lists *** /
- // Mutable variant, for use with Reader.
- trait Consumer[A] {
- def feed(a: A): Unit
- def eof: Unit
- }
- // Immutable variant, for use with State.
- trait Consumer[-A] {
- def feed(a: A): Consumer[A]
- def eof: Consumer[A]
- }
- // Equivalent little DSL, for use with Free.
- trait Producer[S, +A]
- case class Produce[S, A](s: S, a: A)
- type IntProducer[A] = Producer[Int, A]
- // Note that Free[IntProducer, Unit] is equivalent to List[Int]
- // The question is:
- // Why would we ever use List[Int] when State[Consumer[Int], A] works just fine?
Add Comment
Please, Sign In to add comment