Skip to content

Commit 8641462

Browse files
authored
Merge pull request #1 from Altair-Bueno/Altair-Bueno-2097
PR for #2097
2 parents 0fc97e0 + 8fca64c commit 8641462

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

_overviews/scala3-book/control-structures.md

Lines changed: 7 additions & 6 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

461-
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.
461+
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.
464-
In the default case, we return `true` for any other value.
463+
The first one checks whether the given value is either the integer 0, an empty string, null or false and returns false in this case.
464+
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)