Skip to content

Old style Scala 2 If-else expression #2096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 12, 2021
Merged

Conversation

Altair-Bueno
Copy link
Contributor

if (<condition>) <doThis> else <doThat> syntax is from Scala 2. Use if <condition> then <doThis> else <doThat> instead or simplify it by removing the if-else expression. If-else is unnecessary so i removed it. I already tested this code using REPL. It does work as intended

$ scala3-repl
scala> def isNullOrEmpty(s: String): Boolean = s==null || s.trim.equals("")
def isNullOrEmpty(s: String): Boolean

scala> isNullOrEmpty (null)
val res0: Boolean = true

scala> isNullOrEmpty ("")                                                                            
val res3: Boolean = true

scala> isNullOrEmpty ("hello")                                                                     
val res1: Boolean = false

if (<condition>) <doThis> else <doThat> syntax is from Scala 2. Use if <condition> then <doThis> else <doThat> instead or simplify it by removing the if-else expression. If-else is unnecessary
@SethTisue
Copy link
Member

SethTisue commented Jun 24, 2021

nice catch.

also, while we're changing this example, s.trim.equals("") isn't idiomatic Scala. s.trim == "" would be a little better and s.trim.isEmpty would be better still

fyi @alvinj

@Altair-Bueno
Copy link
Contributor Author

@SethTisue i changed s.trim.equals(") to s.trim.isEmpty as you suggested. Should be good to go

@Altair-Bueno
Copy link
Contributor Author

I found another isNullOrEmpty. This time it was using Scala's 3 syntax instead of Scala 2, but i changed it to match 'A taste of Scala' section

Co-authored-by: Philippus Baalman <[email protected]>
@Philippus Philippus merged commit cd6318a into scala:main Jul 12, 2021
@Philippus
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants