The Inbox: Collections-ct.850.mcz

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

The Inbox: Collections-ct.850.mcz

commits-2
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.850.mcz

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

Name: Collections-ct.850
Author: ct
Time: 15 August 2019, 12:57:02.047584 am
UUID: a8581084-5210-3747-8b96-791b0458f52f
Ancestors: Collections-fn.847

Add #collectAll:, which performs a collector on each simply nested element

=============== Diff against Collections-fn.847 ===============

Item was added:
+ ----- Method: Collection>>collectAll: (in category 'enumerating') -----
+ collectAll: aBlock
+ "Loop over all elements of the receiver which must be collections
+ and for each simply nested element, evaluate aBlock. Collect the
+ resulting values into a set. Return the set."
+
+ | result |
+ result := Set new.
+ self
+ collect: aBlock
+ thenDo: [:collection | result addAll: collection].
+ ^ result!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.850.mcz

Jakob Reschke
I don't see why the elements of the receiver must be collections. The result of the block must be a collection. Do the results differ between the following two expressions?

    aCollection collectAll: [:each | ...].
    (aCollection gather: [:each | ...]) asSet.

Am Do., 15. Aug. 2019 um 00:57 Uhr schrieb <[hidden email]>:
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.850.mcz

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

Name: Collections-ct.850
Author: ct
Time: 15 August 2019, 12:57:02.047584 am
UUID: a8581084-5210-3747-8b96-791b0458f52f
Ancestors: Collections-fn.847

Add #collectAll:, which performs a collector on each simply nested element

=============== Diff against Collections-fn.847 ===============

Item was added:
+ ----- Method: Collection>>collectAll: (in category 'enumerating') -----
+ collectAll: aBlock
+       "Loop over all elements of the receiver which must be collections
+       and for each simply nested element, evaluate aBlock. Collect the
+       resulting values into a set. Return the set."
+
+       | result |
+       result := Set new.
+       self
+               collect: aBlock
+               thenDo: [:collection | result addAll: collection].
+       ^ result!




Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.850.mcz

Christoph Thiede

Thank you for the hint! I was not aware of #gather:, so #collectAll: does not really add value. :)


Von: Squeak-dev <[hidden email]> im Auftrag von Jakob Reschke <[hidden email]>
Gesendet: Donnerstag, 15. August 2019 02:07:07
An: [hidden email]
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.850.mcz
 
I don't see why the elements of the receiver must be collections. The result of the block must be a collection. Do the results differ between the following two expressions?

    aCollection collectAll: [:each | ...].
    (aCollection gather: [:each | ...]) asSet.

Am Do., 15. Aug. 2019 um 00:57 Uhr schrieb <[hidden email]>:
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.850.mcz

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

Name: Collections-ct.850
Author: ct
Time: 15 August 2019, 12:57:02.047584 am
UUID: a8581084-5210-3747-8b96-791b0458f52f
Ancestors: Collections-fn.847

Add #collectAll:, which performs a collector on each simply nested element

=============== Diff against Collections-fn.847 ===============

Item was added:
+ ----- Method: Collection>>collectAll: (in category 'enumerating') -----
+ collectAll: aBlock
+       "Loop over all elements of the receiver which must be collections
+       and for each simply nested element, evaluate aBlock. Collect the
+       resulting values into a set. Return the set."
+
+       | result |
+       result := Set new.
+       self
+               collect: aBlock
+               thenDo: [:collection | result addAll: collection].
+       ^ result!




Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.850.mcz

Christoph Thiede

Just one another idea, could we maybe introduce #gather:as:, analogous to #collect:as:?


gather: aBlock as: aClass

^ (aClass inheritsFrom: SequenceableCollection)
ifTrue: [aClass streamContents: [:stream |
self do: [:ea | stream nextPutAll: (aBlock value: ea)]]]
ifFalse: [(self gather: aBlock as: Array) as: aClass]

Best,

Christoph


Von: Squeak-dev <[hidden email]> im Auftrag von Thiede, Christoph
Gesendet: Donnerstag, 15. August 2019 02:20:55
An: [hidden email]
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.850.mcz
 

Thank you for the hint! I was not aware of #gather:, so #collectAll: does not really add value. :)


Von: Squeak-dev <[hidden email]> im Auftrag von Jakob Reschke <[hidden email]>
Gesendet: Donnerstag, 15. August 2019 02:07:07
An: [hidden email]
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.850.mcz
 
I don't see why the elements of the receiver must be collections. The result of the block must be a collection. Do the results differ between the following two expressions?

    aCollection collectAll: [:each | ...].
    (aCollection gather: [:each | ...]) asSet.

Am Do., 15. Aug. 2019 um 00:57 Uhr schrieb <[hidden email]>:
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.850.mcz

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

Name: Collections-ct.850
Author: ct
Time: 15 August 2019, 12:57:02.047584 am
UUID: a8581084-5210-3747-8b96-791b0458f52f
Ancestors: Collections-fn.847

Add #collectAll:, which performs a collector on each simply nested element

=============== Diff against Collections-fn.847 ===============

Item was added:
+ ----- Method: Collection>>collectAll: (in category 'enumerating') -----
+ collectAll: aBlock
+       "Loop over all elements of the receiver which must be collections
+       and for each simply nested element, evaluate aBlock. Collect the
+       resulting values into a set. Return the set."
+
+       | result |
+       result := Set new.
+       self
+               collect: aBlock
+               thenDo: [:collection | result addAll: collection].
+       ^ result!




Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.850.mcz

marcel.taeumel
Hmm... one could implement a gather-version of #fillFrom:with: and use that in #gather:as:? :-)

Best,
Marcel

Am 15.08.2019 16:36:04 schrieb Thiede, Christoph <[hidden email]>:

Just one another idea, could we maybe introduce #gather:as:, analogous to #collect:as:?


gather: aBlock as: aClass

^ (aClass inheritsFrom: SequenceableCollection)
ifTrue: [aClass streamContents: [:stream |
self do: [:ea | stream nextPutAll: (aBlock value: ea)]]]
ifFalse: [(self gather: aBlock as: Array) as: aClass]

Best,

Christoph


Von: Squeak-dev <[hidden email]> im Auftrag von Thiede, Christoph
Gesendet: Donnerstag, 15. August 2019 02:20:55
An: [hidden email]
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.850.mcz
 

Thank you for the hint! I was not aware of #gather:, so #collectAll: does not really add value. :)


Von: Squeak-dev <[hidden email]> im Auftrag von Jakob Reschke <[hidden email]>
Gesendet: Donnerstag, 15. August 2019 02:07:07
An: [hidden email]
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.850.mcz
 
I don't see why the elements of the receiver must be collections. The result of the block must be a collection. Do the results differ between the following two expressions?

    aCollection collectAll: [:each | ...].
    (aCollection gather: [:each | ...]) asSet.

Am Do., 15. Aug. 2019 um 00:57 Uhr schrieb <[hidden email]>:
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.850.mcz

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

Name: Collections-ct.850
Author: ct
Time: 15 August 2019, 12:57:02.047584 am
UUID: a8581084-5210-3747-8b96-791b0458f52f
Ancestors: Collections-fn.847

Add #collectAll:, which performs a collector on each simply nested element

=============== Diff against Collections-fn.847 ===============

Item was added:
+ ----- Method: Collection>>collectAll: (in category 'enumerating') -----
+ collectAll: aBlock
+       "Loop over all elements of the receiver which must be collections
+       and for each simply nested element, evaluate aBlock. Collect the
+       resulting values into a set. Return the set."
+
+       | result |
+       result := Set new.
+       self
+               collect: aBlock
+               thenDo: [:collection | result addAll: collection].
+       ^ result!




Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.850.mcz

Christoph Thiede

Something like this? :)

gather: aBlock as: aClass

^ (aClass new: self size) fillAllFrom: self with: aBlock

fillAllFrom: aCollection with: aBlock
"Evaluate aBlock with each of aCollections's elements as the argument.  
Collect the resulting values into self. Answer self."

aCollection do: [ :each |
self addAll: (aBlock value: each) ]

Not sure how we could speed up things by overriding #fillAllFrom:with: analogously to #fillFrom:with: in Dictionary & ArrayedCollection.


Von: Squeak-dev <[hidden email]> im Auftrag von Taeumel, Marcel
Gesendet: Donnerstag, 15. August 2019 16:42:21
An: gettimothy via Squeak-dev
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.850.mcz
 
Hmm... one could implement a gather-version of #fillFrom:with: and use that in #gather:as:? :-)

Best,
Marcel

Am 15.08.2019 16:36:04 schrieb Thiede, Christoph <[hidden email]>:

Just one another idea, could we maybe introduce #gather:as:, analogous to #collect:as:?


gather: aBlock as: aClass

^ (aClass inheritsFrom: SequenceableCollection)
ifTrue: [aClass streamContents: [:stream |
self do: [:ea | stream nextPutAll: (aBlock value: ea)]]]
ifFalse: [(self gather: aBlock as: Array) as: aClass]

Best,

Christoph


Von: Squeak-dev <[hidden email]> im Auftrag von Thiede, Christoph
Gesendet: Donnerstag, 15. August 2019 02:20:55
An: [hidden email]
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.850.mcz
 

Thank you for the hint! I was not aware of #gather:, so #collectAll: does not really add value. :)


Von: Squeak-dev <[hidden email]> im Auftrag von Jakob Reschke <[hidden email]>
Gesendet: Donnerstag, 15. August 2019 02:07:07
An: [hidden email]
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.850.mcz
 
I don't see why the elements of the receiver must be collections. The result of the block must be a collection. Do the results differ between the following two expressions?

    aCollection collectAll: [:each | ...].
    (aCollection gather: [:each | ...]) asSet.

Am Do., 15. Aug. 2019 um 00:57 Uhr schrieb <[hidden email]>:
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.850.mcz

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

Name: Collections-ct.850
Author: ct
Time: 15 August 2019, 12:57:02.047584 am
UUID: a8581084-5210-3747-8b96-791b0458f52f
Ancestors: Collections-fn.847

Add #collectAll:, which performs a collector on each simply nested element

=============== Diff against Collections-fn.847 ===============

Item was added:
+ ----- Method: Collection>>collectAll: (in category 'enumerating') -----
+ collectAll: aBlock
+       "Loop over all elements of the receiver which must be collections
+       and for each simply nested element, evaluate aBlock. Collect the
+       resulting values into a set. Return the set."
+
+       | result |
+       result := Set new.
+       self
+               collect: aBlock
+               thenDo: [:collection | result addAll: collection].
+       ^ result!




Carpe Squeak!