Have the sort function simply return a lazy list object. When the [4] is called on that object, it knows to do as much work as needed, and can leave the rest as lazy.

--John

Dave Whipp dave-at-whipp.name |Perl 6| wrote:
Lets say I want to find the 5th smallest element in an array. I might write:

  @array.sort.[4];

How does the implementation of the sort function know that I just want to 5th item (and thus choose an appropriate optimization)? Obviously the function could be told that it's caller wants 5 values in list context, but is there a way to get more info than that?


Reply via email to