CollectionsExtensions.kt 452 B

1234567891011121314
  1. package com.ted.weather.extensions
  2. import java.util.*
  3. fun <K, V : Any> Map<K, V?>.toVarargArray(): Array<out Pair<K, V>> =
  4. map({ Pair(it.key, it.value!!) }).toTypedArray()
  5. inline fun <T, R : Any> Iterable<T>.firstResult(predicate: (T) -> R?): R {
  6. for (element in this) {
  7. val result = predicate(element)
  8. if (result != null) return result
  9. }
  10. throw NoSuchElementException("No element matching predicate was found.")
  11. }