Skip to content

Commit 31526a9

Browse files
authored
Merge pull request scala/scala#8142 from dwijnand/prefer-PartialFunction-runWith-over-isDefinedAt-and-apply
Prefer PartialFunction#runWith over isDefinedAt/apply
2 parents cdc3e3b + d89f30d commit 31526a9

File tree

4 files changed

+4
-10
lines changed

4 files changed

+4
-10
lines changed

library/src/scala/collection/immutable/TreeSeqMap.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,7 @@ final class TreeSeqMap[K, +V] private (
250250
while (iter.hasNext) {
251251
val k = iter.next()
252252
val (_, v) = mapping(k)
253-
if (pf.isDefinedAt((k, v))) {
254-
val (k2, v2) = pf((k, v))
255-
bdr.addOne(k2, v2)
256-
}
253+
pf.runWith({ case (k2, v2) => bdr.addOne(k2, v2) })((k, v))
257254
}
258255
bdr.result()
259256
}

library/src/scala/jdk/DoubleAccumulator.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ final class DoubleAccumulator
185185
val s = stepper
186186
while (s.hasStep) {
187187
val n = s.nextStep()
188-
if (pf.isDefinedAt(n))
189-
b.addOne(pf.apply(n))
188+
pf.runWith(b.addOne)(n)
190189
}
191190
b.result()
192191
}

library/src/scala/jdk/IntAccumulator.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ final class IntAccumulator
190190
val s = stepper
191191
while (s.hasStep) {
192192
val n = s.nextStep()
193-
if (pf.isDefinedAt(n))
194-
b.addOne(pf.apply(n))
193+
pf.runWith(b.addOne)(n)
195194
}
196195
b.result()
197196
}

library/src/scala/jdk/LongAccumulator.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ final class LongAccumulator
185185
val s = stepper
186186
while (s.hasStep) {
187187
val n = s.nextStep()
188-
if (pf.isDefinedAt(n))
189-
b.addOne(pf.apply(n))
188+
pf.runWith(b.addOne)(n)
190189
}
191190
b.result()
192191
}

0 commit comments

Comments
 (0)