From c3a58d34c576e4798bc141ac7967117a81331920 Mon Sep 17 00:00:00 2001 From: Altair-Bueno <67512202+Altair-Bueno@users.noreply.github.com> Date: Thu, 24 Jun 2021 19:30:21 +0200 Subject: [PATCH 1/5] Using Scala 2 If-else expression instead if () else syntax is from Scala 2. Use if then else instead or simplify it by removing the if-else expression. If-else is unnecessary --- _overviews/scala3-book/taste-objects.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_overviews/scala3-book/taste-objects.md b/_overviews/scala3-book/taste-objects.md index ae522627f1..5c27e3b8a9 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.equals("") def leftTrim(s: String): String = s.replaceAll("^\\s+", "") def rightTrim(s: String): String = s.replaceAll("\\s+$", "") ``` From 662cf053d5c84f5e11650e4e6787b41ed34c4d08 Mon Sep 17 00:00:00 2001 From: Altair-Bueno <67512202+Altair-Bueno@users.noreply.github.com> Date: Fri, 25 Jun 2021 11:28:03 +0200 Subject: [PATCH 2/5] Added @SethTisue suggestion --- _overviews/scala3-book/taste-objects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_overviews/scala3-book/taste-objects.md b/_overviews/scala3-book/taste-objects.md index 5c27e3b8a9..6e33d8fd55 100644 --- a/_overviews/scala3-book/taste-objects.md +++ b/_overviews/scala3-book/taste-objects.md @@ -27,7 +27,7 @@ For example, this `StringUtils` object contains a small collection of string-rel ```scala object StringUtils: - def isNullOrEmpty(s: String): Boolean = s==null || s.trim.equals("") + def isNullOrEmpty(s: String): Boolean = s==null || s.trim == "" def leftTrim(s: String): String = s.replaceAll("^\\s+", "") def rightTrim(s: String): String = s.replaceAll("\\s+$", "") ``` From 430252a1766eb0062784ad992d78eec516965b27 Mon Sep 17 00:00:00 2001 From: Altair-Bueno <67512202+Altair-Bueno@users.noreply.github.com> Date: Fri, 25 Jun 2021 11:29:44 +0200 Subject: [PATCH 3/5] Update taste-objects.md --- _overviews/scala3-book/taste-objects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_overviews/scala3-book/taste-objects.md b/_overviews/scala3-book/taste-objects.md index 6e33d8fd55..2e6d1428ca 100644 --- a/_overviews/scala3-book/taste-objects.md +++ b/_overviews/scala3-book/taste-objects.md @@ -27,7 +27,7 @@ For example, this `StringUtils` object contains a small collection of string-rel ```scala object StringUtils: - def isNullOrEmpty(s: String): Boolean = s==null || s.trim == "" + 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+$", "") ``` From f8b8af443956c64769a7577ed0882b182ec8d87e Mon Sep 17 00:00:00 2001 From: Altair-Bueno <67512202+Altair-Bueno@users.noreply.github.com> Date: Fri, 25 Jun 2021 13:06:17 +0200 Subject: [PATCH 4/5] Found another Scala 2 `isNullOrEmpty` --- _overviews/scala3-book/domain-modeling-tools.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_overviews/scala3-book/domain-modeling-tools.md b/_overviews/scala3-book/domain-modeling-tools.md index b8fd76f2fc..f59c39c8af 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: From 728d5dc3aed5e8415446d42ce0d5f849f1bdc5f9 Mon Sep 17 00:00:00 2001 From: Altair-Bueno <67512202+Altair-Bueno@users.noreply.github.com> Date: Mon, 12 Jul 2021 13:40:37 +0200 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Philippus Baalman --- _overviews/scala3-book/domain-modeling-tools.md | 2 +- _overviews/scala3-book/taste-objects.md | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/_overviews/scala3-book/domain-modeling-tools.md b/_overviews/scala3-book/domain-modeling-tools.md index f59c39c8af..2319cabf87 100644 --- a/_overviews/scala3-book/domain-modeling-tools.md +++ b/_overviews/scala3-book/domain-modeling-tools.md @@ -219,7 +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 = s==null || s.trim.isEmpty + 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 2e6d1428ca..4fbb325eb2 100644 --- a/_overviews/scala3-book/taste-objects.md +++ b/_overviews/scala3-book/taste-objects.md @@ -27,7 +27,7 @@ For example, this `StringUtils` object contains a small collection of string-rel ```scala object StringUtils: - def isNullOrEmpty(s: String): Boolean = s==null || s.trim.isEmpty + 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+$", "") ``` @@ -92,4 +92,3 @@ NOTE: I don’t know if this is worth keeping, but I’m leaving it here as a co {% endcomment %} -