mapTo

inline fun <T, R, C : MutableCollection<in R>> Iterable<T>.mapTo(destination: C, transform: (T) -> R): C(source)

Appends transformed elements to destination in iteration order.

Applies transform once per element and appends every result, including nulls. Existing destination contents are retained. If iteration, the callback or insertion fails, prior additions remain; the function does not roll them back. The inline callback supports non-local returns. An empty source leaves the destination unchanged.

Receiver

elements to visit in their iteration order.

Return

the same destination instance.

Parameters

destination

mutable collection receiving additions; its insertion rules apply.

transform

transformation receiving the current element.