public inline fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> { return mapTo(ArrayList<R>(collectionSizeOrDefault(10)), transform) }
public fun <T, R> Sequence<T>.map(transform: (T) -> R): Sequence<R>{ return TransformingSequence(this, transform) }
public inline fun <T> Sequence<T>.first(predicate: (T) -> Boolean): T { for (element in this) if (predicate(element)) return element throw NoSuchElementException(“Sequence contains no element matching the predicate.”) }
internal class TransformingIndexedSequence<T, R> constructor(private val sequence: Sequence<T>, private val transformer: (Int, T) -> R) : Sequence<R> {
override fun iterator(): Iterator<R> = object : Iterator<R> { … override fun next(): R { return transformer(checkIndexOverflow(index++), iterator.next()) } … }