Rob Elliot
05/05/2021, 6:18 PMIterable<T>.map
method?
public inline fun <T, R> Collection<T>.map(transform: (T) -> R): List<R> {
return if (this.isEmpty()) emptyList() else (this as Iterable<T>).map(transform)
}
spand
05/06/2021, 5:55 AMRob Elliot
05/07/2021, 10:01 AMpublic inline fun <T> Iterable<T>.all(predicate: (T) -> Boolean): Boolean {
if (this is Collection && isEmpty()) return true
for (element in this) if (!predicate(element)) return false
return true
}
public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean): Boolean {
if (this is Collection && isEmpty()) return false
for (element in this) if (predicate(element)) return true
return false
}
Rob Elliot
05/07/2021, 10:04 AMIterable<T>.map
to this:
public inline fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> {
return if (this is Collection && isEmpty()) emptyList()
else mapTo(ArrayList(collectionSizeOrDefault(10)), transform)
}