guides/coding_style/kotlin/README.md
Your personal library of every algorithm and data structure code that you will ever encounter
(Source)
interface Foo<out T : Any> : Bar {
fun foo(a: Int): T
}
list.filter { it > 10 }.map { element -> element * 2 }
class Person(id: Int, name: String)
class Person(
id: Int,
name: String,
surname: String
) : Human(id, name) {
// ...
}
class Person(
id: Int,
name: String,
surname: String
) : Human(id, name),
KotlinMaker {
// ...
}
If a function returns Unit, the return type should be omitted:
fun foo() { // ": Unit" is omitted here
}
In some cases, functions with no arguments might be interchangeable with read-only properties. Although the semantics are similar, there are some stylistic conventions on when to prefer one to another. Prefer a property over a function when the underlying algorithm: