0

I am trying to sort a List of XMLMessage which in turn, derive from Message. The Message trait extends Ordered and provides comparison function based on timestamps. However, when I try to say:

list.sorted

the error says

error: diverging implicit expansion for type scala.math.Ordering[domain.XMLMessage]
starting with method comparatorToOrdering in trait LowPriorityOrderingImplicits

How can I provide ordering on the Messages so that list.sorted would work? Thanks

1 Answer 1

1

sorted requires an Ordering[XMLMessage], but you (through implicits) can only provide an Ordering[Message]. Ordering is invariant, hence the sort cannot use it. The easiest way to achieve what you want is probably:

list.sortBy(_: Message)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.