Skip to content

@mpilquist /gist:3428731

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Example of trampolining iteratees with scalaz 7
import scalaz._
import Scalaz._
import scalaz.iteratee._
import EnumeratorT._
def counter[A, F[+_]: Pointed] =
IterateeT.fold[A, F, Int](0) { (acc: Int, a: A) => acc + 1 }
def count[A, F[+_]: Monad](e: EnumeratorT[A, F]) =
(counter[A, F] &= e).run
require (count(enumList[Int, Id](List(1, 2, 3))) === 3)
val largeStream = Stream.range(1, 100001, 1)
try {
(counter[Int, Id] &= enumStream[Int, Id](largeStream))
require (false, "Should have thrown stack overflow")
} catch {
case _: StackOverflowError =>
import Free._
require (count(enumList[Int, Trampoline](List(1, 2, 3))).run === 3)
require ((counter[Int, Trampoline] &= enumStream[Int, Trampoline](largeStream)) === largeStream.size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.