ilya.gorbunov
04/21/2016, 4:02 PMlist.filter { predicate(it) }.map { transform(it) }
Here filter evaluates predicate for each element, and after that map performs a transform on each element passed the predicate. By fusing them into a single loop one changes an order of evaluation — now predicate and transform calls are interleaved:
list.forEach {
if (predicate(it))
result.add(transform(it))
}