Drop JavaTypeParameter#getIndex

This commit is contained in:
Alexander Udalov
2015-03-03 11:32:59 +03:00
parent ca8831097f
commit ed022f892b
5 changed files with 23 additions and 20 deletions
@@ -77,6 +77,14 @@ public fun <K, V: Any> Iterable<K>.keysToMapExceptNulls(value: (K) -> V?): Map<K
return map
}
public fun <K> Iterable<K>.mapToIndex(): Map<K, Int> {
val map = LinkedHashMap<K, Int>()
for ((index, k) in this.withIndex()) {
map[k] = index
}
return map
}
public fun <T, C: Collection<T>> C.ifEmpty(body: () -> C): C = if (isEmpty()) body() else this
public fun <T: Any> emptyOrSingletonList(item: T?): List<T> = if (item == null) listOf() else listOf(item)