Pattern? I'd call it an antipattern myself. Note that we can already construct { block1 . block2 . block3 } and write { block1 . block2 . block3 } allSatisfy: [:each | each value]. so we don't have to abuse the #, selector or write a single new method to get the "flattened" structure you're after. Collection methods for: 'collections of blocks' allSatisfied ^self allSatisfy: [:each | each value] anySatisfied ^self anySatisfy: [:each | each value] noneSatisfied ^self noneSatisfy: [:each | each value] if you do feel like adding a few methods, whereupon { block1 . block2 . block3 } allSatisfied Didn't VW recently implement {} syntax natively? Or was that VAST? In all seriousness, when is it better to use ComplexCondition than to rewrite? On Wed, 16 Mar 2022 at 14:38, Hernán Morales Durand < hernan.morales@gmail.com> wrote:
This is an interesting pattern. Thank you for sharing.
Hernán
El mar, 15 mar 2022 a las 4:43, Julián Maestri (<serpi90@gmail.com>) escribió:
Not satisfying the equality, but you can use polymorphism.
Block >> , aBlock ^ BlockCompositor andAll: OrderedCollection with: self with: aBlock
BlockCompositor >> #, aBlock conditions add: aBlock.
BlockCompositor >> value: anObject ^ conditions allSatisfy: [:e | e value: anObject ]
I don't really like the name BlockCompositor, but can't think of a better name at the moment.
You could also implement logic for #or: using #+ and: #anySatisfy: for example, but need to safeguard against mixing both conditions.
On Mon, 14 Mar 2022 at 22:29, Hernán Morales Durand < hernan.morales@gmail.com> wrote:
I think I saw a coding pattern a while ago that allows you to do the following:
cond1 , cond2 , cond3 , cond4
And providing a kind of folding selector condition #and: you would get:
[ cond1 and: [ cond2 and: [ cond3 and: [ cond4 ] ] ] ].
for example:
conditions := [ : each | each firstName = 'Boca' ] , [ : each | each lastName = 'Baret' ] , [ : each | each fullName = 'Virgasia' ].
such that the following assert is met:
self assert: conditions equals: [ : each | each firstName = 'Boca' and: [ each lastName = 'Baret' and: [ each fullName = 'Virgasia' ] ] ].
Any ideas or pointers?
Cheers,
Hernán