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