Skip to content

Instantly share code, notes, and snippets.

@bmjames
Created July 17, 2012 23:16
Show Gist options
  • Save bmjames/3132781 to your computer and use it in GitHub Desktop.
Save bmjames/3132781 to your computer and use it in GitHub Desktop.
Enumerateaser
// Import ALL the things
import scalaz._, Scalaz._, iteratee._, Iteratee._, effect._
// An enumerator based on an iterator
val input = enumIterator[String, IO](Iterator("a", "bb", "ccc", "dddd"))
// An enumeratee which maps strings to their length
def strLen[F[_]:Monad] = EnumerateeT.map[String, Int, F](_.length)
// An iteratee which prints to System.out
val output = putStrTo[Int](System.out) &= (input mapE strLen)
// Prints '1234'
output.run.unsafePerformIO()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment