Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 563 Bytes

ExpressionBodySyntax.md

File metadata and controls

32 lines (22 loc) · 563 Bytes

Pattern: Use of verbose function body

Issue: -

Description

Functions which only contain a return statement can be collapsed to an expression body. This shortens and cleans up the code.

Example of incorrect code:

fun stuff(): Int {
    return 5
}

Example of correct code:

fun stuff() = 5

fun stuff() {
    return
        moreStuff()
            .getStuff()
            .stuffStuff()
}

Further Reading