Skip to content

Instantly share code, notes, and snippets.

View aditrioka's full-sized avatar
🏠
Working from home

Adi Trioka aditrioka

🏠
Working from home
  • Bekasi, Indonesia
  • 20:05 (UTC +07:00)
View GitHub Profile
fun <T> doConditionally(people: MutableList<T>,
condition: (T) -> Boolean,
action: (T) -> Unit) {
people.forEach {
if (condition(it)) action(it)
}
}
val lambda: (Person) -> Boolean = { p -> p.name.startsWith("H") }
//
fun Person.doDance() {
println("*dancing*")
}
val Person.isOld get() = age >= 25
data class Person(val name: String, val gender: Gender,
var age: Int = 0, var email: String = "") {
fun doWork() {
println("*working*")
}
fun doEat() {
println("*eating*")
}