Enumerator[Future, A]
Enumerator[Task, A]
if thats less terrible
fold(())((_, _) => ())
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?