This method did not exist a a couple of years ago. It is too long on the todo list to merge CollectionExtensions into Pharo, but we did not get a chance to do it completely. I do not quite like the ifFound:ifNone: because ifFound: does not sound like the inverse of ifNone:. Better would be detect:ifFound:ifNotFound:, but that would not work well with the established detect:ifNone:. Doru On Tue, May 20, 2014 at 9:47 AM, Sven Van Caekenberghe <sven@stfx.eu> wrote:
I find the selector name somewhat confusing, especially since we already have:
detect: aBlock ifFound: foundBlock ifNone: exceptionBlock "Evaluate aBlock with each of the receiver's elements as the argument. If some element evaluates aBlock to true, then cull this element into foundBlock and answer the result of this evaluation. If none evaluate to true, then evaluate exceptionBlock."
self do: [ :each | (aBlock value: each) ifTrue: [ ^ foundBlock cull: each ] ]. ^ exceptionBlock value
On 20 May 2014, at 09:42, Tudor Girba <tudor@tudorgirba.com> wrote:
Ah, yes :).
Doru
On Tue, May 20, 2014 at 9:38 AM, Stephan Eggermont <stephan@stack.nl> wrote: detect: aBlock ifOne: presentBlock ifNone: noneBlock | result | result := self detect: aBlock ifNone: [nil]. ^ result isNil ifTrue: [ noneBlock value ] ifFalse: [ presentBlock value: result ]
From CollectionExtensions in
MCSmalltalkhubRepository owner: 'Moose' project: 'CollectionExtensions' user: '' password: ''
-- www.tudorgirba.com
"Every thing has its own flow"
-- www.tudorgirba.com "Every thing has its own flow"