Skip to content

Add a SortedSeq collection type #11725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
neontorrent opened this issue Sep 4, 2019 · 0 comments
Closed

Add a SortedSeq collection type #11725

neontorrent opened this issue Sep 4, 2019 · 0 comments

Comments

@neontorrent
Copy link

This is a new proposal for a previously closed issue: scala/collection-strawman#132


Use case:

In the past we had CanBuildFrom that we can pass to map/collect/etc. methods, and turn the collection into something else. I personally use coll.map[B, That] {/* lambda */}(new CanBuildFrom[Coll, B, That] {/* impl */}).sortedBy(_.intField) to sort any Iterable into a sorted Seq.

This is a better performant version than coll.map{/**/}.toSeq.sortedBy(_.intField) as it does not create an intermediate collection Seq

However after 2.13, we no longer have CanBuildFrom to pass into map/collect/etc., and there is no alternative to convert an Iterable to a sorted collection without creating an intermediate Seq.

Proposal:

Since CanBuildFrom is gone for good, I propose we should have a SortedSeq so that the use case above can be achieved with less performance penalty. Then we can do:

val coll: Iterable[String] = List("100", "11")
coll.to(SortedSeq.evidenceIterableFactory(Ordering.by((_: String).toInt)))

This allows duplicate items in the collection, which SortedSet cannot do.

An example of possible implementation can be found at: https://contributors.scala-lang.org/t/new-collection-sortedlist/314/21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant