This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T> doConditionally(people: MutableList<T>, | |
condition: (T) -> Boolean, | |
action: (T) -> Unit) { | |
people.forEach { | |
if (condition(it)) action(it) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val lambda: (Person) -> Boolean = { p -> p.name.startsWith("H") } | |
// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Person.doDance() { | |
println("*dancing*") | |
} | |
val Person.isOld get() = age >= 25 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Person(val name: String, val gender: Gender, | |
var age: Int = 0, var email: String = "") { | |
fun doWork() { | |
println("*working*") | |
} | |
fun doEat() { | |
println("*eating*") | |
} |
NewerOlder