Skip to content

Commit e467a03

Browse files
committed
Add map operation to SimpleIdentitySet
1 parent e599efb commit e467a03

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

compiler/src/dotty/tools/dotc/util/SimpleIdentitySet.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ abstract class SimpleIdentitySet[+Elem <: AnyRef] {
1212
def contains[E >: Elem <: AnyRef](x: E): Boolean
1313
def foreach(f: Elem => Unit): Unit
1414
def exists[E >: Elem <: AnyRef](p: E => Boolean): Boolean
15+
def map[B <: AnyRef](f: Elem => B): SimpleIdentitySet[B]
1516
def /: [A, E >: Elem <: AnyRef](z: A)(f: (A, E) => A): A
1617
def toList: List[Elem]
1718

@@ -55,6 +56,7 @@ object SimpleIdentitySet {
5556
def contains[E <: AnyRef](x: E): Boolean = false
5657
def foreach(f: Nothing => Unit): Unit = ()
5758
def exists[E <: AnyRef](p: E => Boolean): Boolean = false
59+
def map[B <: AnyRef](f: Nothing => B): SimpleIdentitySet[B] = empty
5860
def /: [A, E <: AnyRef](z: A)(f: (A, E) => A): A = z
5961
def toList = Nil
6062
}
@@ -69,6 +71,8 @@ object SimpleIdentitySet {
6971
def foreach(f: Elem => Unit): Unit = f(x0.asInstanceOf[Elem])
7072
def exists[E >: Elem <: AnyRef](p: E => Boolean): Boolean =
7173
p(x0.asInstanceOf[E])
74+
def map[B <: AnyRef](f: Elem => B): SimpleIdentitySet[B] =
75+
Set1(f(x0.asInstanceOf[Elem]))
7276
def /: [A, E >: Elem <: AnyRef](z: A)(f: (A, E) => A): A =
7377
f(z, x0.asInstanceOf[E])
7478
def toList = x0.asInstanceOf[Elem] :: Nil
@@ -86,6 +90,8 @@ object SimpleIdentitySet {
8690
def foreach(f: Elem => Unit): Unit = { f(x0.asInstanceOf[Elem]); f(x1.asInstanceOf[Elem]) }
8791
def exists[E >: Elem <: AnyRef](p: E => Boolean): Boolean =
8892
p(x0.asInstanceOf[E]) || p(x1.asInstanceOf[E])
93+
def map[B <: AnyRef](f: Elem => B): SimpleIdentitySet[B] =
94+
Set2(f(x0.asInstanceOf[Elem]), f(x1.asInstanceOf[Elem]))
8995
def /: [A, E >: Elem <: AnyRef](z: A)(f: (A, E) => A): A =
9096
f(f(z, x0.asInstanceOf[E]), x1.asInstanceOf[E])
9197
def toList = x0.asInstanceOf[Elem] :: x1.asInstanceOf[Elem] :: Nil
@@ -114,6 +120,8 @@ object SimpleIdentitySet {
114120
}
115121
def exists[E >: Elem <: AnyRef](p: E => Boolean): Boolean =
116122
p(x0.asInstanceOf[E]) || p(x1.asInstanceOf[E]) || p(x2.asInstanceOf[E])
123+
def map[B <: AnyRef](f: Elem => B): SimpleIdentitySet[B] =
124+
Set3(f(x0.asInstanceOf[Elem]), f(x1.asInstanceOf[Elem]), f(x2.asInstanceOf[Elem]))
117125
def /: [A, E >: Elem <: AnyRef](z: A)(f: (A, E) => A): A =
118126
f(f(f(z, x0.asInstanceOf[E]), x1.asInstanceOf[E]), x2.asInstanceOf[E])
119127
def toList = x0.asInstanceOf[Elem] :: x1.asInstanceOf[Elem] :: x2.asInstanceOf[Elem] :: Nil
@@ -156,6 +164,8 @@ object SimpleIdentitySet {
156164
}
157165
def exists[E >: Elem <: AnyRef](p: E => Boolean): Boolean =
158166
xs.asInstanceOf[Array[E]].exists(p)
167+
def map[B <: AnyRef](f: Elem => B): SimpleIdentitySet[B] =
168+
SetN(xs.map(x => f(x.asInstanceOf[Elem]).asInstanceOf[AnyRef]))
159169
def /: [A, E >: Elem <: AnyRef](z: A)(f: (A, E) => A): A =
160170
xs.asInstanceOf[Array[E]].foldLeft(z)(f)
161171
def toList: List[Elem] = {

0 commit comments

Comments
 (0)