[squeak-dev] Collections/Streams | About enumerating a sequence up to a matching query ...
Nicolas Cellier
nicolas.cellier.aka.nice at gmail.com
Mon Mar 8 22:33:13 UTC 2021
I like that, it's beginning to be expressive, even better than clojure.
However, i think that clojure offers composable predicates thanks to
lazyness... like Xtreams.
Le lun. 8 mars 2021 à 21:38, Jaromir Matas <m at jaromir.net> a écrit :
> > I am looking for something like #collect:until: or #upToSatisfying:. I do
> want the stop element to be included here, not sure about the general case.
> >
> > aButton withAllOwners
> > collect: [:morph | morph color]
> > until: [:morph | morph isSystemWindow].
> >
>
> Hi again, ahh so you're actually looking for a generalized collect for any
> SequencableCollection or Stream :) Like this?
>
> (1 to: 100)
> collect: [:x | x squared]
> where: [:x | x even]
> until: [:x | x squared = 2500]
>
>
> collect: collectBlock where: whereBlock until: untilBlock
>
> | result supplier |
> supplier := self readStream.
> result := {} writeStream.
> [[supplier atEnd]
> whileFalse: [ | val |
> val := supplier next.
> (whereBlock value: val) ifTrue: [result nextPut:
> (collectBlock value:
> val)].
> (untilBlock value: val) ifTrue: [^result contents]]
> ] value.
> ^result contents
>
> collect: colBlock until: untilBlock
>
> ^self collect: colBlock where: [:each | true] until: untilBlock
>
> or even:
>
> collect: colBlock
>
> ^self collect: colBlock until: [:each | true]
>
>
>
>
> -----
> ^[^ Jaromir
> --
> Sent from: http://forum.world.st/Squeak-Dev-f45488.html
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210308/916d2fb1/attachment.html>
More information about the Squeak-dev
mailing list
|