<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. 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>> Date: Fri, 29 Jun 2007 15:56:26 +0100<br>> From: pdcawley@bofh.org.uk<br>> To: squeak-dev@lists.squeakfoundation.org<br>> Subject: Does anyone else have this pattern?<br>> <br>> During my SmallLint directed exploration of the guts of the<br>> OmniBrowser, I came across a chunk of code that looked (very<br>> approximately like)<br>> <br>> coll := self buildCollection.<br>> <br>> coll ifEmpty: [^ self].<br>> coll size = 1 ifTrue: [self browse: coll first].<br>> self askUserToChooseFrom: coll.<br>> <br>> Now, call me Mr Fussy, but I really don't like seeing function scoped<br>> temporaries if I can help it, so it seems to me that one could write a<br>> method on Collection along the lines of:<br>> <br>> ifEmpty: emptyBlock ifSingular: singularBlock otherwise: otherwiseBlock<br>> <br>> self ifEmpty [^ emptyBlock value].<br>> ^self size = 1<br>> ifTrue: [singularBlock valueWithPossibleArgument: self first]<br>> ifFalse: [otherwiseBlock valueWithPossibleArgument: self]<br>> <br>> Which would clean the original method up like so:<br>> <br>> self buildCollection<br>> ifEmpty: []<br>> ifSingular: [:node| self browse: node]<br>> otherwise: [:coll| self askUserToChooseFrom: col]<br>> <br>> Which, to my eyes at least, seems to express the intent more clearly.<br>> <br>> The obvious rearrangements and subsets spring to mind, along with<br>> otherwiseDo:, otherwiseInject:, otherwiseCollect:<br>> <br>> So, am I alone in thinking something like this would be useful, and if<br>> I'm not, what's the best way to go about getting it into the image?<br>> Create a CollectionTesting package and add it to the dependencies of<br>> any packages that use it? Submit a changeset somewhere? And enquiring<br>> mind wants to know.<br>> <br>> Thanks in advance for your consideration.<br>> <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>