Collection withAllSubclasses collect: #numberOfLinesOfCode
is the equicalent to
Collection withAllSubclasses collect: [:each | each numberOfLinesOfCode ]
What happens below is that (unary) symbols are polymorphic with one
parameters blocks, i.e. they understand cull: and value:, which is
^anObject perform: self.
So in fact what will hapen is more like
Collection withAllSubclasses collect: [:each | each perform:
... which is a bit slower than the traditional block version so you might
want to think if that makes a difference in your case.
You can use symbols whenever a unary block is expected, for example in most
collection enumerating methods, such as do:, select:, reject:, allSatisfy:,
detect:, ... (see 'enumerating' protocol in Collection class for more
All this methods send value: (or maybe cull:) to the received block
argument, so you can pass an unary symbol instead (or even whatever object
that understands value:).
On Mon, Sep 19, 2016 at 12:12 PM, frankl1_miky <mike1corporat...@gmail.com>
> I'll like to know what is happening exactly in background when I'm using a
> symbol as in *Collection withAllSubclasses collect: #numberOfLinesOfCode*.
> I also want to know the other cases where I can use symbol.
> Is there any tutorial about using symbol?
> View this message in context: http://forum.world.st/Using-
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.