I noted that in C#, the following LINQ code: ```ve...
# stdlib
k
I noted that in C#, the following LINQ code:
Copy code
veryLargeList.Order().Take(10).ToList();
Does a Quickselect/partial Quicksort to avoid having to sort the entire array. Is there any chance that Kotlin Sequences can be optimized in the same way?
Copy code
veryLargeList.asSequence().sorted().take(10).toList()
y
Currently, no, because it just returns an anonymous object. Theoretically, I don't see why there can't be a custom sequence subclass for it, and
take
can check for that and optimize it. An alternative would be a
sorted(10)
method that specifically did quickselect
k
It’d be nice if something like this used a priority queue to heapify the elements so you only needed to sort the amount you request.
y
I am sometimes disappointed that Sequence methods just convert to a list sometimes. It kind of ruins the point of Sequences for me, but alas.
👍 2
k
I mean since this is an implementation detail it could definitely be changed.