Situation:
A stream (RxScala) of events, which we are batching using tumblingBuffer() and then building the complete history of for debugging. Ultimately I want these in (Seq[T], Seq[T]) of all the values, so I created the following function as the accumulator to a foldLeft:
def tupleConcat[S](a: (Seq[S], Seq[S]), b: (Seq[S], Seq[S])) = (a._1 ++ b._1, a._2 ++ b._2)
Now, this to me set off a bunch of warning bells after having read Runar & Paul's Functional Programming in Scala, since this looks an awful lot like a map2 of two monoid instances, but I am still a bit stuck on how to generalize it properly. So far, I think it might look something like:
def tupleConcatSG[S](a: (S,S), b: (S,S))(implicit s: Semigroup[S]) = (a._1 |+| b._1, a._2 |+| b._2)
(but I'd have to promote my Seq to IndexedSeq from what I can gather).
To generalize further to any Applicative, I think I'd need an instance for tuples, which perhaps comes from Shapeless? Or am I missing something obvious?
EDIT: I should also add that I am trying to avoid zipping and unzipping, based on prejudicial performance concerns, but perhaps I should not worry about that... (each tumblingBuffer's worth of (Seq,Seq) will be ~15,000 long, and the final (Seq,Seq) ought to be in the millions).