Skip to content

Optimize guard unwrapping expressions #21

@angelolloqui

Description

@angelolloqui

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)
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions