(1) As it happens, my Smalltalk library *does* have
    #excludes: and #identityExcludes:
(2) The definitions are trivial.
    excludes: item
      ^(self includes: item) not
    identityExcludes: item
      ^(self identityIncludes: item) not

If you want to execute aBlock when aString is not all zeros
and ones, just do
   (aString allSatisfy: [:each | each = $0 or: [each = $1]])
     ifFalse: [aBlock value].
or
   (aString anySatisfy: [:each | each ~= $0 and: [each ~= $1]])
     ifTrue: [aBlock value].
or
   ('01' includesAll: aString) ifFalse: [aBlock value].


On Sat, 16 Mar 2019 at 11:33, Tim Mackinnon <tim@testit.works> wrote:

> Hi - in my quest to understand the edgier details of Pharo (and Smalltalk)
> - and driven by fresh thoughts of completing exercism exercises - I was
> surprised to find that there is no #excludes: operation on collection to
> mirror the #includes: operation?
>
> I was curious about this - its seems a strange omission?
>
> Of course I can inverse it with not, or do things a different way - but we
> have ifTrue: mirrored with ifFalse, empty/notEmpty so am I missing
> something?
>
> I wanted to write something like
>
>
> aString detect: [:c | ($0 to: $1) excludes: c] ifFound: aBlock. (Evaluate
> a block if the string isn’t all 0 and 1’s)
>
>
> Of course I can write this as:
>
> (aString reject: [:c | c = $0 | c = $1)) ifNotEmpty: aBlock
>
> But as recent messages in this vein have shown me (and taught me lots -
> thanks to those answering), the answer is often not what I thought.
>
> Tim
>
>
>

Reply via email to