Enumerator
is for all intents and purposes infinite
I figured I better bring this topic to iteratee channel. As mentioned in Circe channel, I want to produce json with Circe in a streaming fashion. I’ve tried to start and faced one question. Basically I need a function like this (imports omitted):
def writeJson[T: Encoder](enum: Enumerator[Task, T], file: File): Task[Unit] = {
val printer = Printer.noSpaces.copy(dropNullKeys = true)
val opener = Enumerator.enumOne[Task, String]("[")
val closer = Enumerator.enumOne[Task, String]("]")
val entries = enum.map(_.asJson.pretty(printer) + ",")
opener.append(entries).append(closer).into(writeLines(file))
}
The problem is the comma after the last entry, which makes the resulting json invalid. Is there a way to somehow introspect the Enumerator and to know if that’s the last entry, to handle it differently?
Iteratee
, Enumeratee
and Enumerator
, what they do on their own and how they interact with each other. IIRC you’ve promised a blog post about Iteratee architecture some time ago (no pressure! :smile: ) , but in absence of it, could you please explain here what they are and what they do, in general?