Created
January 10, 2018 19:00
-
-
Save ascii766164696D/8d4b9e6e56195629e377cf7cbd6599e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object TestReturn { | |
def t(n: Int): Boolean = { | |
(1 to n).map(x => { | |
if (x > 5) return true | |
false | |
}).exists(_ == true) | |
} | |
} | |
object TestReturn2 { | |
def t(n: Int): Boolean = { | |
(1 to n).map(x => | |
if (x > 5) { | |
true | |
} else { | |
false | |
} | |
).exists(_ == true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's an example of when it works not the way we expected
But it should've returned
true
since we're past5
And this returns correct result, since it actually goes all the way to the last element