The Inbox: Collections-mt.941.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Collections-mt.941.mcz

commits-2
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)]!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-mt.941.mcz

Christoph Thiede

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] -> [#>]} )]

Still, the example is rather fictive ...

Best,
Christoph

Von: Squeak-dev <[hidden email]> im Auftrag von [hidden email] <[hidden email]>
Gesendet: Mittwoch, 14. April 2021 14:51:12
An: [hidden email]
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)]!




Carpe Squeak!