Skip to content
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

Lambda expressions with returns #69

Closed
angelolloqui opened this issue Mar 17, 2018 · 1 comment
Closed

Lambda expressions with returns #69

angelolloqui opened this issue Mar 17, 2018 · 1 comment

Comments

@angelolloqui
Copy link
Owner

Kotlin does not use return statements inside lambdas in the same way than Swift. In Kotlin, the last expression is automatically returned, and the return expression is invalid unless used with return@<function_name>.

Examples:

ints.map { return "test" }

Should just be

ints.map { "test" }

And returns inside the body like:

ints.map {
   if $0 == 0 {
        return "zero"
   } 
   return "non zero"
}
ints.map {
   if (it == 0) {
        return@map "zero"
   } 
   "non zero"
}
@angelolloqui
Copy link
Owner Author

Implemented with 2a78f48

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

No branches or pull requests

1 participant