Skip to content

Instantly share code, notes, and snippets.

@mandubian
Created June 11, 2012 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mandubian/2909163 to your computer and use it in GitHub Desktop.
Save mandubian/2909163 to your computer and use it in GitHub Desktop.
Iteratee.mkString
def mkString[E](start: String, sep: String, end: String): Iteratee[E, String] = {
def step(s: String, isFirst: Boolean)(input: Input[E]): Iteratee[E, String] = {
input match {
case Input.EOF => Done(s + end, Input.EOF)
case Input.Empty => Cont(step(s, isFirst))
case Input.El(e) => { val s1 = if(isFirst) { s + e.toString } else { s + sep + e.toString }; Cont[E, String](i => step(s1, false)(i)) }
}
}
Cont(step(start, true))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment