This post originated from an RSS feed registered with Agile Buzz
by James Robertson.
Original Post: One Bag, Two Bag, Three Bag, Four...
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Since I used a Bag post for the first time in production code, I've been on the lookout for repeat occurences. And now I've used them twice (ok, thrice kindof) since.
The first in previous versions of ExtraIcons. They were used to gather the results of the tests for a given class, so that it could compute what kind of test tube to put next to the class. The second, was in repeating the same pattern for feedback for SUnitToo (thus the "kindof").
Tonite I used it in production code for another neat trick. I had a collection of objects. I wanted to enumerate those which were duplicates. So I used:
They're both one liners, about the same. In the end it boils down to how you think about the problem. The second is "make a first pass to find elements that have counts greater than one and then enumerate them". The first one is more like "make a histogram; decrement it, and then enumerate them." I work with histograms and the like, so that seemed kinda natural to me.
I was SO going to be better about regular Smalltalk related blogging this week. Sigh.