3 ms·
list.filter { it % 2 == 0}.map { it + 2 } Does `list.filter { it % 2 == 0}` dynamically create a list or an iterator or what does it do?
by VaxWithSex 5y ago
list.filter { it % 2 == 0}.map { it + 2 }
Does `list.filter { it % 2 == 0}` dynamically create a list or an iterator or what does it do?
- brabel 5y agoYou've got to be careful in Kotlin. if `list` is an actual `List`, `filter` and `map` will create intermediate lists. To avoid that you must use `list.asSequence().filter { .. }.map { .. }.toList()`.
- chess_buster 5y agoThen the code is not the same of what smalltalk does with #select:thenCollect: Smalltalk's Collection classes have a method #species which return what class to use as the new container.