@@ -338,7 +338,7 @@ This is incomplete but should compile;
338
338
def countGroup(s: Shape): Int = s match
339
339
case Rectangle(w, h) => 0
340
340
case Location(x, y, c) => ???
341
- case Group(shapes @ _ *) => ???
341
+ case Group(shapes*) => ???
342
342
343
343
As expected, ``countGroup `` returns 0 for rectangles but would raise a ``NYI `` exception for group or location nodes.
344
344
@@ -354,7 +354,7 @@ Accordingly:
354
354
def countGroup(s: Shape): Int = s match
355
355
case Rectangle(w, h) => 0
356
356
case Location(x, y, c) => countGroup(c)
357
- case Group(shapes @ _ *) =>
357
+ case Group(shapes*) =>
358
358
var sum = 1
359
359
for c <- shapes do
360
360
sum += countGroup(c)
@@ -365,7 +365,7 @@ Equivalently, we can use the ``foreach`` method instead of the so-called for com
365
365
366
366
.. code-block :: scala
367
367
368
- case Group(shapes @ _ *) =>
368
+ case Group(shapes*) =>
369
369
var sum = 1
370
370
shapes.foreach { c =>
371
371
sum += countGroup(c)
@@ -376,7 +376,7 @@ Now...drum roll...we have an opportunity to convert this code into functional, a
376
376
377
377
.. code-block :: scala
378
378
379
- case Group(shapes @ _ *) =>
379
+ case Group(shapes*) =>
380
380
1 + shapes.map { c => countGroup(c) } .sum
381
381
382
382
where map transforms each item in a collection with the result of applying the given function to the item and sum adds all the items in a collection.
0 commit comments