Skip to content

Commit 8788ccf

Browse files
authored
Merge pull request #2154 from Altair-Bueno/main
Control Structures- Description does not match function's signature #2097
2 parents ee172b7 + 193b1c7 commit 8788ccf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

_overviews/scala3-book/control-structures.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,22 +450,23 @@ speak(Person("Bam Bam")) // "Bam Bam says, Bam bam!"
450450
### Using a `match` expression as the body of a method
451451

452452
Because `match` expressions return a value, they can be used as the body of a method.
453-
This method takes a `Boolean` value as an input parameter, and returns a `String`, based on the result of the `match` expression:
453+
This method takes a `Matchable` value as an input parameter, and returns a `Boolean`, based on the result of the `match` expression:
454454

455455
```scala
456456
def isTruthy(a: Matchable) = a match
457-
case 0 | "" => false
458-
case _ => true
457+
case 0 | "" | false => false
458+
case _ => true
459459
```
460460

461461
The input parameter `a` is defined to be the [`Matchable` type][matchable]---which is the root of all Scala types that pattern matching can be performed on.
462462
The method is implemented by matching on the input, providing two cases:
463-
The first one checks whether the given value is either the integer `0` or an empty string and returns `false` in this case.
463+
The first one checks whether the given value is either the integer `0`, an empty string or `false` and returns `false` in this case.
464464
In the default case, we return `true` for any other value.
465465
These examples show how this method works:
466466

467467
```scala
468468
isTruthy(0) // false
469+
isTruthy(false) // false
469470
isTruthy("") // false
470471
isTruthy(1) // true
471472
isTruthy(" ") // true

0 commit comments

Comments
 (0)