Hi --
Is there a better way to get a limited number of elements from a collection but accept less if the collection is not big enough?
someObjects size >= 5 ifTrue: [someObjects first: 5] ifFalse: [someObjects].
Could we add a #firstOrLess:? Similar thoughts on #firstOrNil, #lastOrNil, and #lastOrLess:.
Best, Marcel
-- View this message in context: http://forum.world.st/firstOrLess-and-lastOrLess-tp4847874.html Sent from the Squeak - Dev mailing list archive at Nabble.com.
Hi Marcel--
Is there a better way to get a limited number of elements from a collection but accept less if the collection is not big enough?
Traditionally, that would be Stream>>nextAvailable:.
-C
-- Craig Latta netjam.org +31 6 2757 7177 (SMS ok) + 1 415 287 3547 (no SMS)
The name firstOrLess: is a little confusing. Maybe something like collectMax:
Karl
On Thu, Sep 3, 2015 at 1:30 PM, marcel.taeumel Marcel.Taeumel@hpi.de wrote:
Hi --
Is there a better way to get a limited number of elements from a collection but accept less if the collection is not big enough?
someObjects size >= 5 ifTrue: [someObjects first: 5] ifFalse: [someObjects].
Could we add a #firstOrLess:? Similar thoughts on #firstOrNil, #lastOrNil, and #lastOrLess:.
Best, Marcel
-- View this message in context: http://forum.world.st/firstOrLess-and-lastOrLess-tp4847874.html Sent from the Squeak - Dev mailing list archive at Nabble.com.
It's no "collect" but a "first: n", which returns the first n elements from a collection. So #nextAvailable: reads nice but this is stream semantics. There is no #next for collections.
-- View this message in context: http://forum.world.st/firstOrLess-and-lastOrLess-tp4847874p4847907.html Sent from the Squeak - Dev mailing list archive at Nabble.com.
If you *DID* implement a new method, I'd call it, "upToFirst:".
someObjects upToFirst: 5
However, I don't think its worth expanding the API; I would just do
someObject first: (5 min: someObject size)
It's not that hard to read.
On Thu, Sep 3, 2015 at 9:32 AM, marcel.taeumel Marcel.Taeumel@hpi.de wrote:
It's no "collect" but a "first: n", which returns the first n elements from a collection. So #nextAvailable: reads nice but this is stream semantics. There is no #next for collections.
-- View this message in context: http://forum.world.st/firstOrLess-and-lastOrLess-tp4847874p4847907.html Sent from the Squeak - Dev mailing list archive at Nabble.com.
Sent from my iPhone
On Sep 3, 2015, at 7:40 AM, Chris Muller asqueaker@gmail.com wrote:
If you *DID* implement a new method, I'd call it, "upToFirst:".
someObjects upToFirst: 5
I find this slightly ambiguous with upTo: and upThrough:. Why not atMostFirst: and atMostLast: ?
However, I don't think its worth expanding the API; I would just do
someObject first: (5 min: someObject size)
It's not that hard to read.
On Thu, Sep 3, 2015 at 9:32 AM, marcel.taeumel Marcel.Taeumel@hpi.de wrote: It's no "collect" but a "first: n", which returns the first n elements from a collection. So #nextAvailable: reads nice but this is stream semantics. There is no #next for collections.
-- View this message in context: http://forum.world.st/firstOrLess-and-lastOrLess-tp4847874p4847907.html Sent from the Squeak - Dev mailing list archive at Nabble.com.
On 9/3/15, Eliot Miranda eliot.miranda@gmail.com wrote:
Sent from my iPhone
On Sep 3, 2015, at 7:40 AM, Chris Muller asqueaker@gmail.com wrote:
If you *DID* implement a new method, I'd call it, "upToFirst:".
someObjects upToFirst: 5
I find this slightly ambiguous with upTo: and upThrough:. Why not atMostFirst: and atMostLast: ?
+1
However, I don't think its worth expanding the API; I would just do
someObject first: (5 min: someObject size)
It's not that hard to read.
On Thu, Sep 3, 2015 at 9:32 AM, marcel.taeumel Marcel.Taeumel@hpi.de wrote: It's no "collect" but a "first: n", which returns the first n elements from a collection. So #nextAvailable: reads nice but this is stream semantics. There is no #next for collections.
-- View this message in context: http://forum.world.st/firstOrLess-and-lastOrLess-tp4847874p4847907.html Sent from the Squeak - Dev mailing list archive at Nabble.com.
squeak-dev@lists.squeakfoundation.org