Skip to content

Commit bf2c559

Browse files
committed
updated vararg syntax, fixes #32
Signed-off-by: Konstantin Läufer <[email protected]>
1 parent b09bb4a commit bf2c559

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

source/functionalprogramming.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ This is incomplete but should compile;
338338
def countGroup(s: Shape): Int = s match
339339
case Rectangle(w, h) => 0
340340
case Location(x, y, c) => ???
341-
case Group(shapes @ _*) => ???
341+
case Group(shapes*) => ???
342342
343343
As expected, ``countGroup`` returns 0 for rectangles but would raise a ``NYI`` exception for group or location nodes.
344344

@@ -354,7 +354,7 @@ Accordingly:
354354
def countGroup(s: Shape): Int = s match
355355
case Rectangle(w, h) => 0
356356
case Location(x, y, c) => countGroup(c)
357-
case Group(shapes @ _*) =>
357+
case Group(shapes*) =>
358358
var sum = 1
359359
for c <- shapes do
360360
sum += countGroup(c)
@@ -365,7 +365,7 @@ Equivalently, we can use the ``foreach`` method instead of the so-called for com
365365

366366
.. code-block:: scala
367367
368-
case Group(shapes @ _*) =>
368+
case Group(shapes*) =>
369369
var sum = 1
370370
shapes.foreach { c =>
371371
sum += countGroup(c)
@@ -376,7 +376,7 @@ Now...drum roll...we have an opportunity to convert this code into functional, a
376376

377377
.. code-block:: scala
378378
379-
case Group(shapes @ _*) =>
379+
case Group(shapes*) =>
380380
1 + shapes.map { c => countGroup(c) } .sum
381381
382382
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

Comments
 (0)