[NI] Add feature for choosing candidate by lambda return type

This commit is contained in:
Dmitriy Novozhilov
2020-04-22 13:15:49 +03:00
parent f243b8946f
commit 865ddac07a
19 changed files with 429 additions and 23 deletions
@@ -148,4 +148,17 @@ inline fun <T, R, C : MutableCollection<in R>> Iterable<T>.flatMapToNullable(des
}
fun <E : Enum<E>> min(a: E, b: E): E = if (a < b) a else b
fun <E : Comparable<E>> min(a: E, b: E): E = if (a < b) a else b
fun <E : Comparable<E>> min(a: E, b: E): E = if (a < b) a else b
inline fun <T, R> Iterable<T>.same(extractor: (T) -> R): Boolean {
val iterator = iterator()
val firstValue = extractor(iterator.next())
while (iterator.hasNext()) {
val item = iterator.next()
val value = extractor(item)
if (value != firstValue) {
return false
}
}
return true
}