Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

feeding two iteratee with one enumerator

I'm very new to play framework, functional programming and Iteratee I/O, so maybe my question is very out of topic or even stupid.

I would like to upload big text files as stream to a third party and in the same time extract Meta Data about this file (based on its content, to simplify said it's a csv file).

I've already written two working body parsers: Iteratee[Array[Byte], B] that contains the writing logic and an Iteratee[Array[Byte], MetaData] that contains the MetaData extracting logic. Could you please tell me how to combine these two parsers to handle Writing and extracting content in the same time

like image 234
OrP Avatar asked Oct 06 '22 14:10

OrP


1 Answers

If you have two iteratees, it1 and it1, say, you can created a "zipped" iteratee from them (zippedIt in the code below) that will send whatever input it receives to both iteratees, it1 and it2. See the Play Iteratee documentation of zip.

Here's an example:

import play.api.libs.iteratee.{Enumerator, Iteratee, Enumeratee}

val e = Enumerator("1", "2", "3")
val it1 = Iteratee.foreach[String](v => println("1: " + v))
val it2 = Iteratee.foreach[String](v => println("2: " + v))
val zippedIt = Enumeratee.zip(it1, it2)
e(zippedIt)

The console output of this small snippet is:

1: 1
2: 1
1: 2
2: 2
1: 3
2: 3
like image 110
Hbf Avatar answered Oct 10 '22 03:10

Hbf