Re: [Pharo-dev] blog post explaining the codecity visualization of pharo changes
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: ''
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"
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"
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"
But that does't work in the case the object you are looking for nil... (Ok, maybe that's not a really relevant case...) This version however handles the case, detect: aBlock ifOne: presentBlock ifNone: noneBlock | result | result := self detect: aBlock ifNone: [ ^ noneBlock value ]. ^ presentBlock value: result Guille 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: ''
Cool. I integrated your suggestion. Thanks, Doru On Tue, May 20, 2014 at 9:43 AM, Guillermo Polito <guillermopolito@gmail.com
wrote:
But that does't work in the case the object you are looking for nil... (Ok, maybe that's not a really relevant case...)
This version however handles the case,
detect: aBlock ifOne: presentBlock ifNone: noneBlock | result | result := self detect: aBlock ifNone: [ ^ noneBlock value ]. ^ presentBlock value: result
Guille
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"
participants (4)
-
Guillermo Polito -
Stephan Eggermont -
Sven Van Caekenberghe -
Tudor Girba