I'm trying to use scalaz-stream
to process multiple files simultaneously, applying a single function to each line in the files, across all the files.
For concreteness, suppose I have a function that takes a list of strings
def f(lines: Seq[String]): Something = ???
And a couple of files, the first:
foo1
foo2
foo3
the second:
bar1
bar2
bar3
The result of the whole process should be:
List(
f(Seq("foo1", "bar1")),
f(Seq("foo2", "bar2")),
f(Seq("foo3", "bar3"))
)
(or more likely written directly into some other file)
The number of files is not known beforehand, and the number of lines may vary between the different files, but I'm okay with padding (at runtime) the ends of the shorter files with a default values, or cutting out the longer files.
So essentially, I need a way to combine a Seq[Process[Task, String]]
(obtained via something like io.linesR
) into a single Process[Task, Seq[String]]
.
What would be the simplest way to achieve that?
Or, more generally, how do I combine n
instances of Process[F, I]
into a single instance Process[F, Seq[I]]
?
I'm sure there's some standard combinator for this purpose, but I wasn't able to figure it out...
Thanks.