Thank you! That is a keeper.


However, I had to add a reset to get the first one to work becuase it appears the Stream runs to the end at each iteration of the Array.


|ios|
ios := ReadStream on: 'Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...|-'.

{ '{|'  . '|-' . '|}' . '{{' . '}}' .  '[[' . ']]' . '__' . '==' . '::' . '**' . '##' . ''''  } anySatisfy: [:pattern | ios match: pattern. ios reset].



The second form is not detecting the the '|-'  at the end, as far as I can tell.

|ios|
ios := ReadStream on: 'Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...|-'.
{ '{|'  . '|-' . '|}' . '{{' . '}}' .  '[[' . ']]' . '__' . '==' . '::' . '**' . '##' . '''' }
    detect: [:pattern | ios match: pattern]
    ifFound: [:pattern | self inform: 'Matched pattern: ' , pattern.]
    ifNone: [self inform: 'no match'. ].
  ios reset
cheers,
t




---- On Sat, 27 Nov 2021 11:36:49 -0500 Thiede, Christoph <Christoph.Thiede@student.hpi.uni-potsdam.de> wrote ----

What about


{ '{|'  . '|-' . '|}' . '{{' . '}}' .  '[[' . ']]' . '__' . '==' . '::' . '**' . '##' . '''' } anySatisfy: [:pattern | self match: pattern]


?


Maybe also this one if the identity of the matching pattern is of interest:


{ '{|'  . '|-' . '|}' . '{{' . '}}' .  '[[' . ']]' . '__' . '==' . '::' . '**' . '##' . '''' }

    detect: [:pattern | self match: pattern]

    ifFound: [:pattern | self inform: 'Matched pattern: ' , pattern]

    ifNone: [self inform: 'no match']


Best,

Christoph


PS: Don't use #| unless you explicitly want every method to be invoked always. Use #or:... instead, this is faster.


Von: Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von gettimothy via Squeak-dev <squeak-dev@lists.squeakfoundation.org>
Gesendet: Samstag, 27. November 2021 17:30:38
An: squeak-dev
Betreff: [squeak-dev] Anybody got an elegent construct for this functional monstrosity?
 
I have a ReadStream and I want to detect some substrings in it.

This works, but it is ugly.


((self match:'{|') |
(self match:'|-') |
(self match:'|}') |
(self match:'{{') |
(self match:'}}') |
(self match:'[[') |
(self match:']]') |
(self match:'__') |
(self match:'==') |
(self match:'::') |
(self match:'**') |
(self match:'##') |
(self match:'''') )

Is anybody aware of an elegant approach to this?


Something along the lines of 


self matchAny: { '{|'  . '|-' . '|}' . '{{' . '}}' .  '[[' . ']]' . '__' . '==' . '::' . '**' . '##' . '''' }


thx in advance