[Cuis-dev] Additional collection methods reject:thenDo: and reject:thenCollect:
Gerald Klix
cuis.01 at klix.ch
Fri Mar 7 09:38:48 PST 2025
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250307/8f78c09d/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MoreEnumeration.pck.st
Type: application/vnd.sailingtracker.track
Size: 6208 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250307/8f78c09d/attachment-0002.st>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MoreEnumerationTest.pck.st
Type: application/vnd.sailingtracker.track
Size: 3271 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250307/8f78c09d/attachment-0003.st>
More information about the Cuis-dev
mailing list