[squeak-dev] Anybody got an elegent construct for this functional monstrosity?

Thiede, Christoph Christoph.Thiede at student.hpi.uni-potsdam.de
Sat Nov 27 16:36:49 UTC 2021


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 at lists.squeakfoundation.org> im Auftrag von gettimothy via Squeak-dev <squeak-dev at 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20211127/48f67b1b/attachment.html>


More information about the Squeak-dev mailing list