Using subList for drop and take methods on lists

As we can see in the source code drop, take, 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 drop and take methods, you can use subList in the implementation instead of creating a new list and also keep performance advantages of a list.

It is true, @momt99,
at same time we have to consider that subList is a view of original one, so can lead to unexpected results and it is -definitively- an incompatible change.

So, is there any plan to implement something similar to subList but in a managed way?

I think the main problem is that kotlin is creating a new list for Iterables. It could use the same implementation for Sequence and Iterable with some customized instructions for special data structures. Like what we can see in Streams of java or Linq of C#.

Iterable.drop/take returns List, so it can’t be implemented same as for Sequence.

I don’t think it’s possible to achieve both requirements and stay within the current contract of these functions.