<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body>
I like this sort of pattern, but I wouldn't put it in the stock image.&nbsp; I would make it an extension of whatever project uses it (i.e. it might be in Collection but under the protocol *Your-Project-Name), or maybe make a new project called "Collection extension" or something.<br><br>&gt; Date: Fri, 29 Jun 2007 15:56:26 +0100<br>&gt; From: pdcawley@bofh.org.uk<br>&gt; To: squeak-dev@lists.squeakfoundation.org<br>&gt; Subject: Does anyone else have this pattern?<br>&gt; <br>&gt; During my SmallLint directed exploration of the guts of the<br>&gt; OmniBrowser, I came across a chunk of code that looked (very<br>&gt; approximately like)<br>&gt; <br>&gt; coll := self buildCollection.<br>&gt; <br>&gt; coll ifEmpty: [^ self].<br>&gt; coll size = 1 ifTrue: [self browse: coll first].<br>&gt; self askUserToChooseFrom: coll.<br>&gt; <br>&gt; Now, call me Mr Fussy, but I really don't like seeing function scoped<br>&gt; temporaries if I can help it, so it seems to me that one could write a<br>&gt; method on Collection along the lines of:<br>&gt; <br>&gt; ifEmpty: emptyBlock ifSingular: singularBlock otherwise: otherwiseBlock<br>&gt; <br>&gt;     self ifEmpty [^ emptyBlock value].<br>&gt;     ^self size = 1<br>&gt;         ifTrue: [singularBlock valueWithPossibleArgument: self first]<br>&gt;         ifFalse: [otherwiseBlock valueWithPossibleArgument: self]<br>&gt; <br>&gt; Which would clean the original method up like so:<br>&gt; <br>&gt; self buildCollection<br>&gt;     ifEmpty: []<br>&gt;     ifSingular: [:node| self browse: node]<br>&gt;     otherwise: [:coll| self askUserToChooseFrom: col]<br>&gt; <br>&gt; Which, to my eyes at least, seems to express the intent more clearly.<br>&gt; <br>&gt; The obvious rearrangements and subsets spring to mind, along with<br>&gt; otherwiseDo:, otherwiseInject:, otherwiseCollect:<br>&gt; <br>&gt; So, am I alone in thinking something like this would be useful, and if<br>&gt; I'm not, what's the best way to go about getting it into the image?<br>&gt; Create a CollectionTesting package and add it to the dependencies of<br>&gt; any packages that use it? Submit a changeset somewhere? And enquiring<br>&gt; mind wants to know.<br>&gt; <br>&gt; Thanks in advance for your consideration.<br>&gt; <br><br /><hr />Hotmail to go? Get your Hotmail, news, sports and much more!   <a href='http://mobile.msn.com' target='_new'>Check out the New MSN Mobile</a></body>
</html>