The Artima Developer Community
Sponsored Link

Agile Buzz Forum
One Bag, Two Bag, Three Bag, Four...

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
One Bag, Two Bag, Three Bag, Four... Posted: Dec 10, 2004 9:58 AM
Reply to this message Reply

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
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement
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:

((original asBag) removeAll: original asSet; yourself) asSet do: [:each | "blah"]

Works like a charm. Yes, I recognized that I could have also used:

(original asSet select: [:each | (original occurencesOf: each) > 1]) do: [:each | "blah"]

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.

Read: One Bag, Two Bag, Three Bag, Four...

Topic: A common misconception Previous Topic   Next Topic Topic: How To Create A Custom Widget - Dynamic Look Change

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use