Skip to content

Instantly share code, notes, and snippets.

@markhibberd
Created June 5, 2011 15:37
Show Gist options
  • Save markhibberd/1009060 to your computer and use it in GitHub Desktop.
Save markhibberd/1009060 to your computer and use it in GitHub Desktop.
Int Enumerator
import scalaz._, Scalaz._
import IterV._
// something to generate a stream that will be enough to blow the stack....
def ints[A]: (Int, Int) => IterV[Int, A] => IterV[Int, A] = (start, end) => iter => {
def loop(s: Int, i: IterV[Int, A]): IterV[Int, A] = i match {
case Done(_, _) => i
case Cont(k) =>
if (s > end)
i
else
loop(s + 1, k(El(s)))
}
loop(start, iter)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment