You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Using a `match` expression as the body of a method
451
451
452
452
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:
454
454
455
455
```scala
456
456
defisTruthy(a: Matchable) = a match
457
-
case0|""=>false
458
-
case _ =>true
457
+
case0|""|false=>false
458
+
case _ =>true
459
459
```
460
460
461
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.
462
462
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.
464
464
In the default case, we return `true` for any other value.
0 commit comments