I'm trying to write a function that maps a sequence S by a function F (I'll call it F(S)), zips the resulting values (F(S)) with S, and sorts the result by F(S), returning the sorted zipped values (I hope the code clears this up, it's difficult to put into text)
Here's my current code:
def sortByAndReturnZippedMetric[S,M<:Ordering[AnyVal]]( s:Seq[S], mapper:S=>M):Seq[(M,S)] =
s.map(mapper).zip(s).sortBy(_._1)
Scalac is complaining, though:
error: diverging implicit expansion for type scala.math.Ordering[M]
starting with method comparatorToOrdering in trait LowPriorityOrderingImplicits
s.map(mapper).zip(s).sortBy(_._1)
^
I'd appreciate some pointers as to what might be wrong...