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 |
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) |
In reply to this post by marcel.taeumel
The name firstOrLess: is a little confusing. Maybe something like collectMax: Karl On Thu, Sep 3, 2015 at 1:30 PM, marcel.taeumel <[hidden email]> wrote: Hi -- |
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.
|
> ...#nextAvailable: reads nice but this is stream semantics. There is > no #next for collections. That was a suggestion that you should be using a stream. :) -C -- Craig Latta netjam.org +31 6 2757 7177 (SMS ok) + 1 415 287 3547 (no SMS) |
In reply to this post by marcel.taeumel
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> wrote:
> > > Sent from my iPhone > >> On Sep 3, 2015, at 7:40 AM, Chris Muller <[hidden email]> 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 <[hidden email]> >>> 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. >>> >> > > |
Free forum by Nabble | Edit this page |