Skip to content

Commit cd6318a

Browse files
authored
Merge pull request #2096 from Altair-Bueno/patch-1
Old style Scala 2 If-else expression
2 parents 0400f52 + 728d5dc commit cd6318a

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

_overviews/scala3-book/domain-modeling-tools.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ Here’s an example of a “string utilities” object that contains a set of me
219219
object StringUtils:
220220
def truncate(s: String, length: Int): String = s.take(length)
221221
def containsWhitespace(s: String): Boolean = s.matches(".*\\s.*")
222-
def isNullOrEmpty(s: String): Boolean =
223-
if s == null || s.trim.equals("") then true else false
222+
def isNullOrEmpty(s: String): Boolean = s == null || s.trim.isEmpty
224223
```
225224

226225
We can use the object as follows:

_overviews/scala3-book/taste-objects.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ For example, this `StringUtils` object contains a small collection of string-rel
2727

2828
```scala
2929
object StringUtils:
30-
def isNullOrEmpty(s: String): Boolean =
31-
if (s==null || s.trim.equals("")) true else false
30+
def isNullOrEmpty(s: String): Boolean = s == null || s.trim.isEmpty
3231
def leftTrim(s: String): String = s.replaceAll("^\\s+", "")
3332
def rightTrim(s: String): String = s.replaceAll("\\s+$", "")
3433
```
@@ -93,4 +92,3 @@ NOTE: I don’t know if this is worth keeping, but I’m leaving it here as a co
9392
{% endcomment %}
9493

9594

96-

0 commit comments

Comments
 (0)