[squeak-dev] The Inbox: Collections-mt.941.mcz

Thiede, Christoph Christoph.Thiede at student.hpi.uni-potsdam.de
Wed Apr 14 15:10:52 UTC 2021


Nice idea! Hmm... I can't figure out a real example, maybe something like this?


(1 to: 20) asArray shuffled
    do: [:ea | Transcript show: ea]
    separatedBy: [:prev :next | Transcript show: ( prev <=> next caseOf: {
        [-1] -> [#<]. [0] -> [#=]. [1] -> [#>]} )]
<http://www.hpi.de/>

Still, the example is rather fictive ...

Best,
Christoph
________________________________
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von commits at source.squeak.org <commits at source.squeak.org>
Gesendet: Mittwoch, 14. April 2021 14:51:12
An: squeak-dev at lists.squeakfoundation.org
Betreff: [squeak-dev] The Inbox: Collections-mt.941.mcz

A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-mt.941.mcz

==================== Summary ====================

Name: Collections-mt.941
Author: mt
Time: 14 April 2021, 2:51:04.673628 pm
UUID: 93df256c-2d6c-e246-87aa-4296ff9c993d
Ancestors: Collections-ul.940

(Not a) proposal. In #do:separatedBy: optionally provide the elements around that separation to the block. Looks like an interleaved combination of #do: and #overlappingPairsDo:.

Here is a (not convincing) example:

(1 to: 20)
        do: [:num | Transcript showln: num]
        separatedBy: [:a :b | Transcript showln: a+b]

Maybe this is something. Haven't found a good example yet.

=============== Diff against Collections-ul.940 ===============

Item was changed:
  ----- Method: Collection>>do:separatedBy: (in category 'enumerating') -----
  do: elementBlock separatedBy: separatorBlock
         "Evaluate the elementBlock for all elements in the receiver,
         and evaluate the separatorBlock between."

+        | beforeFirst lastSeen |
-        | beforeFirst |
         beforeFirst := true.
         self do:
                 [:each |
                 beforeFirst
                         ifTrue: [beforeFirst := false]
+                        ifFalse: [separatorBlock cull: lastSeen cull: each].
+                elementBlock value: each.
+                lastSeen := each]!
-                        ifFalse: [separatorBlock value].
-                elementBlock value: each]!

Item was changed:
  ----- Method: SequenceableCollection>>do:separatedBy: (in category 'enumerating') -----
  do: elementBlock separatedBy: separatorBlock
         "Evaluate the elementBlock for all elements in the receiver,
         and evaluate the separatorBlock between."

+        | lastSeen |
         1 to: self size do:
                 [:index |
+                index = 1 ifFalse: [separatorBlock cull: lastSeen cull: (self at: index)].
+                lastSeen := self at: index.
+                elementBlock value: lastSeen]!
-                index = 1 ifFalse: [separatorBlock value].
-                elementBlock value: (self at: index)]!


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


More information about the Squeak-dev mailing list