[Cuis-dev] Additional collection methods reject:thenDo: and reject:thenCollect:

Ezequiel Birman ebirman77 at gmail.com
Fri Mar 7 11:04:27 PST 2025


Always in favour of modularity and stripping the core of unused messages.

On Fri, 7 Mar 2025 at 17:39, Gerald Klix via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:

> On 3/7/25 5:24 PM, Ezequiel Birman via Cuis-dev wrote:
>
> Hello
>
> I wanted a *reject:thenDo:*. so instead of:
>
> | taskbar userInterface |
>
> "If we were to ommit this, the taskbar wouldn't exist yet, and therefore
> taskbar would be initialized to nil"
> *self runningWorld doOneCycleNow.*
>
>
> *userInterface := UISupervisor ui.taskbar := userInterface taskbar.*
>
> "Remove all morphs except for the taskbar. We also leave code windows
> intact in case we are recovering from a crash."
> *userInterface submorphs*
> *    select: [ :morph | (morph isKindOf: CodeWindow) not and: [ morph ~=
> taskbar ]]*
> *    thenDo: #delete.*
>
> I can rewrite:
>
>
> "Remove all morphs except for the taskbar. We also leave code windows
> intact in case we are recovering from a crash."
> *userInterface submorphs*
> *    reject: [ :morph | (morph isKindOf: CodeWindow) or: [ morph = taskbar
> ]]*
> *    thenDo: #delete.*
>
> While I was at it, I refactored *select:ThenCollect:* to avoid iterating
> twice, then added a *reject:thenCollect:* just for the sake of symmetry.
>
> I attach the changeset in case you find it useful; but I wanted to know
> what is your opinion on adding tests that exercise higher-level messages
> like these. If they are needed or wanted, I can also add them to
> BaseImageTests.
>
>
>
> Hi Ezequiel, Hello List Members,
>
> what do think about a package that adds some extensions methods
> to the collection classes? I attached such a package and its test package.
>
> Its focus is currently on adding something similar
> to Python's list comprehensions to Cuis/Haver.
>
> This code (https://hg.sr.ht/~cy-de-fect/GF3/browse/gf/base.py?rev=tip#L290
> ):
>
>         def dominates(dom, sub,
>                       orders=tuple(dict((t, i) for i, t in enumerate(mro))
>                                    for mro in mros)):
>             if dom is sub:
>                 return False
>             return all(order[d] <= order[s]
>                        for d, s, order in zip(dom, sub, orders))
>
>
> roughly translates to this piece of Cuis code:
>
>             orders := someHierarchies collect: [ :hierarchy | | order |
>                 order := Dictionary ofRoom: hierarchy size.
>                 hierarchy withIndexDo: [ :type :index | order at: type
> put: index ].
>                 order ].
>             dominates := [ :dom :sub |
>                 dom ~~ sub and: [
>                     { dom. sub. orders } zippedAllSatisfy: [ :d :s :order |
>                         (order at: d) <= (order at: s) ] ] ].
>
>
> Have fun and Best Regards,
>
> Gerald
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250307/89703016/attachment.htm>


More information about the Cuis-dev mailing list