Skip to content

Commit 3a5bbca

Browse files
committed
conflict resolution
2 parents 730e6d8 + 5aa9510 commit 3a5bbca

File tree

6 files changed

+80
-7
lines changed

6 files changed

+80
-7
lines changed

compat/src/main/scala-2.11/scala/collection/compat/package.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
package scala.collection
1414

1515
import scala.collection.generic.{CanBuildFrom, GenericOrderedCompanion, IsTraversableLike}
16+
1617
import scala.runtime.Tuple2Zipped
18+
import scala.collection.{immutable => i}
1719
import scala.{collection => c}
1820

1921
package object compat extends compat.PackageShared {
@@ -49,4 +51,8 @@ package object compat extends compat.PackageShared {
4951
implicit def toTuple2ZippedExtensionMethods[El1, Repr1, El2, Repr2](self: Tuple2Zipped[El1, Repr1, El2, Repr2])
5052
: Tuple2ZippedExtensionMethods[El1, Repr1, El2, Repr2] =
5153
new Tuple2ZippedExtensionMethods[El1, Repr1, El2, Repr2](self)
54+
implicit def toImmutableQueueExtensionMethods[A](
55+
self: i.Queue[A]): ImmutableQueueExtensionMethods[A] =
56+
new ImmutableQueueExtensionMethods[A](self)
57+
5258
}

compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,21 @@ class TraversableLikeExtensionMethods[A, Repr](private val self: c.GenTraversabl
329329
def tapEach[U](f: A => U)(implicit bf: CanBuildFrom[Repr, A, Repr]): Repr =
330330
self.map(a => { f(a); a })
331331

332+
def partitionMap[A1, A2, That, Repr1, Repr2](f: A => Either[A1, A2])(
333+
implicit bf1: CanBuildFrom[Repr, A1, Repr1],
334+
bf2: CanBuildFrom[Repr, A2, Repr2]
335+
): (Repr1, Repr2) = {
336+
val l = bf1()
337+
val r = bf2()
338+
self.foreach { x =>
339+
f(x) match {
340+
case Left(x1) => l += x1
341+
case Right(x2) => r += x2
342+
}
343+
}
344+
(l.result(), r.result())
345+
}
346+
332347
def groupMap[K, B, That](key: A => K)(f: A => B)(
333348
implicit bf: CanBuildFrom[Repr, B, That]): Map[K, That] = {
334349
val map = m.Map.empty[K, m.Builder[B, That]]
@@ -392,3 +407,8 @@ class MapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](
392407
def filterKeys(p: K => Boolean): IterableView[(K, V), C] =
393408
self.filter { case (k, _) => p(k) }
394409
}
410+
411+
class ImmutableQueueExtensionMethods[A](private val self: i.Queue[A]) extends AnyVal {
412+
def enqueueAll[B >: A](iter: c.Iterable[B]): i.Queue[B] =
413+
self.enqueue(iter.to[i.Iterable])
414+
}

compat/src/main/scala-2.12/scala/collection/compat/package.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import scala.collection.generic.{CanBuildFrom, GenericOrderedCompanion, IsTraver
1616
import scala.{collection => c}
1717
import scala.collection.{mutable => m}
1818
import scala.runtime.Tuple2Zipped
19+
import scala.collection.{immutable => i, mutable => m}
20+
1921

2022
package object compat extends compat.PackageShared {
2123
implicit class MutableTreeMapExtensions2(private val fact: m.TreeMap.type) extends AnyVal {
@@ -60,5 +62,9 @@ package object compat extends compat.PackageShared {
6062
implicit def toTuple2ZippedExtensionMethods[El1, Repr1, El2, Repr2](self: Tuple2Zipped[El1, Repr1, El2, Repr2])
6163
: Tuple2ZippedExtensionMethods[El1, Repr1, El2, Repr2] =
6264
new Tuple2ZippedExtensionMethods[El1, Repr1, El2, Repr2](self)
65+
66+
implicit def toImmutableQueueExtensionMethods[A](
67+
self: i.Queue[A]): ImmutableQueueExtensionMethods[A] =
68+
new ImmutableQueueExtensionMethods[A](self)
6369
}
6470

compat/src/test/scala/test/scala/collection/CollectionTest.scala

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class CollectionTest {
3636
val bT: BitSet = b
3737
assertEquals(BitSet(1, 2, 3), b)
3838

39-
val c = xs.to(PriorityQueue)
40-
val cT: PriorityQueue[Int] = c
39+
val c = xs.to(PriorityQueue)
40+
val cT: PriorityQueue[Int] = c
4141
assert(PriorityQueue(1, 2, 3) sameElements c)
4242

4343
val ys = List(1 -> "a", 2 -> "b")
@@ -48,8 +48,8 @@ class CollectionTest {
4848
assertTrue(m.isInstanceOf[Map[_, _]])
4949

5050
// Stream.to(Seq) doesn't evaluate the stream
51-
val strm = 1 #:: {throw new Exception("not lazy")} #:: Stream.empty[Int]
52-
val strmsq: Seq[Int] = strm.to(Seq)
51+
val strm = 1 #:: { throw new Exception("not lazy") } #:: Stream.empty[Int]
52+
val strmsq: Seq[Int] = strm.to(Seq)
5353
var strmln: LinearSeq[Int] = strm.to(LinearSeq)
5454
}
5555

@@ -101,10 +101,23 @@ class CollectionTest {
101101
assertEquals(Map(3 -> 3, 4 -> 1), res)
102102
}
103103

104+
@Test
105+
def partitionMapTest(): Unit = {
106+
val empty = Seq.empty[Int].partitionMap(Right(_))
107+
assertEquals((Seq(), Seq()), empty)
108+
109+
val res = Seq("foo", "test", "bar", "baz")
110+
.partitionMap {
111+
case s if s.contains("a") => Left(s)
112+
case s => Right(s.length)
113+
}
114+
assertEquals((Seq("bar", "baz"), Seq("foo".length, "test".length)), res)
115+
}
116+
104117
@Test
105118
def tapEach(): Unit = {
106119
var count = 0
107-
val it = Iterator(1, 2, 3).tapEach(count += _)
120+
val it = Iterator(1, 2, 3).tapEach(count += _)
108121
assertEquals(0, count)
109122
it.foreach(_ => ())
110123
assertEquals(6, count)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package test.scala.collection
14+
15+
import org.junit.Assert._
16+
import org.junit.Test
17+
18+
import scala.collection.compat._
19+
import scala.collection.immutable.Queue
20+
21+
class ImmutableQueueTest {
22+
23+
@Test
24+
def testEnqueueAll: Unit = {
25+
val q = Queue(1, 2)
26+
val i: Iterable[Int] = List(3, 4)
27+
val eq = q.enqueueAll(i)
28+
assertEquals(Queue(1, 2, 3, 4), eq)
29+
}
30+
}

compat/src/test/scala/test/scala/collection/LazyZipTest.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package test.scala.collection
22

33
import org.junit.Assert.assertEquals
4-
import org.junit.Assert.assertTrue
5-
import org.junit.Assert.assertFalse
64
import org.junit.Test
75

86
import scala.collection.compat._

0 commit comments

Comments
 (0)