diff --git a/_overviews/scala3-book/domain-modeling-tools.md b/_overviews/scala3-book/domain-modeling-tools.md index b8fd76f2fc..2319cabf87 100644 --- a/_overviews/scala3-book/domain-modeling-tools.md +++ b/_overviews/scala3-book/domain-modeling-tools.md @@ -219,8 +219,7 @@ Here’s an example of a “string utilities” object that contains a set of me object StringUtils: def truncate(s: String, length: Int): String = s.take(length) def containsWhitespace(s: String): Boolean = s.matches(".*\\s.*") - def isNullOrEmpty(s: String): Boolean = - if s == null || s.trim.equals("") then true else false + def isNullOrEmpty(s: String): Boolean = s == null || s.trim.isEmpty ``` We can use the object as follows: diff --git a/_overviews/scala3-book/taste-objects.md b/_overviews/scala3-book/taste-objects.md index ae522627f1..4fbb325eb2 100644 --- a/_overviews/scala3-book/taste-objects.md +++ b/_overviews/scala3-book/taste-objects.md @@ -27,8 +27,7 @@ For example, this `StringUtils` object contains a small collection of string-rel ```scala object StringUtils: - def isNullOrEmpty(s: String): Boolean = - if (s==null || s.trim.equals("")) true else false + def isNullOrEmpty(s: String): Boolean = s == null || s.trim.isEmpty def leftTrim(s: String): String = s.replaceAll("^\\s+", "") def rightTrim(s: String): String = s.replaceAll("\\s+$", "") ``` @@ -93,4 +92,3 @@ NOTE: I don’t know if this is worth keeping, but I’m leaving it here as a co {% endcomment %} -