In Kotlin 1.4, I have a Sequence
of Sequence
s. The items in the inner Sequences are already sorted by one of their properties (id
).
I want to merge them into one Sequence
which would also be sorted by the same property.
It's quite trivial algorithm (always taking the smallest of the next items from all sequences). But I was wondering:
Does Kotlin standard library have a stateless sequence merging operation for pre-sorted Sequence
s? Something like Sequence<Sequence<T>>.flattenSorted(c: Comparator)
or so.
Edit:
As some have correctly assumed from the context, I am not looking for flattenSorted()
, which is stateful, does not leverage the pre-sort, and for, say, 100 sequences of 1_000_000 elements, it wouldn't perform too well. I've reworded the question.