Scala SortedSet - sorted by one Ordering and unique by something else?

一个人想着一个人 提交于 2019-12-05 02:51:08

What I do in such situations is this:

val orderByLength = Ordering[(Int, String)].on[String](s => s.length -> s)

In other words, use a tuple to get a tie-breaker.

On the other hand, I think it's silly of SortedSet to consider elements the same based on their ordering. I think this has been discussed before, but I wouldn't discard the possibility of searching mailing lists archives and the scala trac for discussions/tickets on this, and maybe trying to get SortedSet to change its behavior.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!