As we can see in the source code
filter, … extension methods on
Iterables are creating a new list and add items to them. This can be an overhead for large lists and other containers.
A solution could be using
asSequence and calling methods on the sequence to prevent list generations but it costs losing performance advantages in methods such as
indexOfLast which has special implementation for lists.
But especially for
take methods, you can use
subList in the implementation instead of creating a new list and also keep performance advantages of a list.