Skip to content
This repository was archived by the owner on Oct 16, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion style.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,34 @@ override fun toString(): String {
override fun toString(): String = "Hey"
```

Expression functions should not wrap to two lines. If an expression function grows to require wrapping, use a normal function body, a `return` declaration, and normal expression wrapping rules instead.
If an expression function's return grows to require wrapping, use a normal function body, a `return` declaration, and normal expression wrapping rules instead.

```kotlin
// Okay
fun veryVeryLongFun() =
callsAVeryVeryLongFunctionWithHorribleName(andTonsAndTonsOfParameters)

// WRONG!
fun veryVeryLongFun() =
callsAVeryVeryLongFunctionWithHorribleName(andTonsAndTonsOfParameters,
andMoreParameters)

// Okay
fun veryVeryLongFun() {
return callsAVeryVeryLongFunctionWithHorribleName(andTonsAndTonsOfParameters,
andMoreParameters)
}
```

Multiline expression functions are allowed providing it returns a single expression.

```kotlin
fun getFoo(index: Int) = when (index) {
in 0..10 -> "foo"
in 11..20 -> "bar"
else -> "baz"
}
```

### Properties

Expand Down