Quick and dirty lazy lists in Ruby

18 06 2009

Hash.new with a block is a sexy beast: you can specify default hash values and when a key is first used, the value will be calculated and inserted into the Hash. Based on that behavior I took a couple of minutes to hack together a small proof of concept class for lazy lists:

As I said, this is quick and dirty, especially since you have to pass the entire Hash.new block to LazyList.new right now. Other than that I quite like it though. I know there are at least two other lazy list implementations for Ruby, but it seems like both haven’t been updated in a while and I don’t particularly like their interfaces. Dunno, if I manage to simplify list definition, I may actually try to develop this into something. Don’t hold your breath though…



Trackbacks


No Trackbacks

Comments

Display comments as (Linear | Threaded)
No comments

Add Comment


Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Textile-formatting allowed

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA 1CAPTCHA 2CAPTCHA 3CAPTCHA 4CAPTCHA 5


Standard emoticons like :-) and ;-) are converted to images.