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

Optimize guard unwrapping expressions #21

Closed
angelolloqui opened this issue Oct 18, 2017 · 1 comment
Closed

Optimize guard unwrapping expressions #21

angelolloqui opened this issue Oct 18, 2017 · 1 comment

Comments

@angelolloqui
Copy link
Owner

Kotlin allows ternary operators to return.

This code:

func showTenants() {
    guard let intent = coordinator.tenantsIntent() else {
        return
    }
    navigationManager.show(intent, animation: .push)
}

Translates to

fun showTenants() {
    val intent = coordinator.tenantsIntent()
    if (intent == null) {
        return
    }
    navigationManager.show(intent, animation = .push)
}

But could be

fun showTenants() {
    val intent = coordinator.tenantsIntent() ?: return
    navigationManager.show(intent, animation = .push)
}
@angelolloqui angelolloqui changed the title Optimize guard and if unwrapping expressions Optimize guard unwrapping expressions Nov 5, 2017
angelolloqui added a commit that referenced this issue Nov 5, 2017
@angelolloqui
Copy link
Owner Author

Implemented on 2cb30dc

angelolloqui added a commit that referenced this issue Nov 6, 2017
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