Skip to content

Add implicit: genericOrderedCompanionToCBF #249

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

Merged
merged 1 commit into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@

package scala.collection

import scala.collection.generic.IsTraversableLike
import scala.collection.generic.{CanBuildFrom, GenericOrderedCompanion, IsTraversableLike}
import scala.{collection => c}

package object compat extends compat.PackageShared {
implicit def genericOrderedCompanionToCBF[A, CC[X] <: Traversable[X]](
fact: GenericOrderedCompanion[CC])(
implicit ordering: Ordering[A]): CanBuildFrom[Any, A, CC[A]] =
CompatImpl.simpleCBF(fact.newBuilder[A])

implicit def toTraversableLikeExtensionMethods[Repr](self: Repr)(
implicit traversable: IsTraversableLike[Repr])
: TraversableLikeExtensionMethods[traversable.A, Repr] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

package scala.collection

import scala.collection.generic.IsTraversableLike
import scala.collection.generic.{CanBuildFrom, GenericOrderedCompanion, IsTraversableLike}
import scala.{collection => c}
import scala.collection.{mutable => m}

Expand All @@ -27,6 +27,11 @@ package object compat extends compat.PackageShared {
build(m.SortedMap.newBuilder[K, V], source)
}

implicit def genericOrderedCompanionToCBF[A, CC[X] <: Traversable[X]](
fact: GenericOrderedCompanion[CC])(
implicit ordering: Ordering[A]): CanBuildFrom[Any, A, CC[A]] =
CompatImpl.simpleCBF(fact.newBuilder[A])

implicit def toTraversableLikeExtensionMethods[Repr](self: Repr)(
implicit traversable: IsTraversableLike[Repr])
: TraversableLikeExtensionMethods[traversable.A, Repr] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.junit.Test

import scala.collection.compat._
import scala.collection.immutable.BitSet
import scala.collection.mutable.PriorityQueue
import scala.collection.LinearSeq

class CollectionTest {
Expand All @@ -35,6 +36,10 @@ class CollectionTest {
val bT: BitSet = b
assertEquals(BitSet(1, 2, 3), b)

val c = xs.to(PriorityQueue)
val cT: PriorityQueue[Int] = c
assert(PriorityQueue(1, 2, 3) sameElements c)

val ys = List(1 -> "a", 2 -> "b")
val m = ys.to(Map)
// Not possible - `to` returns a Col[A] so this is only typed as an Iterable[(Int, String)]
Expand Down