|Syntactic Confectionery Delight|
Re^6: Better mousetrap (getting top N values from list X)by BrowserUk (Patriarch)
|on Feb 04, 2005 at 00:04 UTC||Need Help??|
Okay. I see what you are saying now. The slice across the return from sort generates a lazy list.
So the code:
Passes the whole list of data to sort, (which takes a copy of it in case we modify or discard it) and returns an iterator which gets bound to @top, so that each time we access the next element of @top in the for loop, the iterator is called via the magic of tieing, and the copy of the 100,000 elements that we passed to sort gets scanned to produce the next of our 5 return values.
Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.