We have a small Scala project on Playframework. I'm trying to do everything reactive, and stumbled on a problem.
I have two Enumerator[A] instances, representing values from a DB ordered by date. I need to return them as a single Enumerator[A] keeping date ordering. I have not found any solution for that in Enumerator[A], so I'm accumulating A's in single collection, and ordering them afterwards.
case class A(
created: Date,
data: String
)
val as: Enumerator[A] = findByAOrderedByCreated()
val bs: Enumerator[A] = findByBOrderedByCreated()
What is reactive way to deal with this?
Here is a solution that will work for any number of
Enumerator
values using anyOrdering
on the elements:It creates an
Iteratee
to apply to eachEnumerator
that is passed in, and anEnumerator
to give the sorted elements. TheIteratee
instances and theEnumerator
communicate by sendingPromise
instances to each other (hence thePromise[Promise[IterateeReturn]]
and such).