bryonnicoson
2/16/2018 - 10:09 PM

Kotlin Lambda

fun filterOldCarsLambda() {
  cars.filter { c -> c.productionYear <= 2010 }
  cars.elementAtOrElse(1) {Car("default", 2011)}
}

// Kotlin filter method - returns a list containing only elements matching given predicate
public inline fun <T> Iterable<T>.filter(predicate: (T) -> Boolean: List<T> {
  return filterTo(ArrayList<T>(), predicate)
}
// End Kotlin filter method


fun lambdasAndClosures() {
  var counter = 0
  var incrementAction = { counter++ }
}

fun createRunnable(): Runnable = Runnable { print("hey, I'm a Runnable created with lambda") }