As you might know, if you wanted to grab the lowest entry from a list, lst.sort().first() is extremely inefficient compared to lst.select(1). Grabbing the first sorted entry is the selection algorithm for k=1 [1]
My hunch is that due to the halting problem, incompleteness, and Entscheidungsproblem, it would be extremely difficult, if not impossible, to do such high level optimization. But I would like to hear what HN has to say. Thanks!
[1] https://en.wikipedia.org/wiki/Selection_algorithm
[2] https://en.wikipedia.org/wiki/Entscheidungsproblem