I thought about that for my own Smalltalk, but then realised
that I didn't know whether #upTo:timesSelect: was bounding
the number of elements *considered* or the number of elements
in the *result*, and I could argue either way.  Arguably the cleanest
way would be to have something like
 (LimitedEnumerableAdapter on: collection limit: anInteger)
    do: aBlock
    select: aBlock
    collect: aBlock
   ... *any* existing or new collection method.


On 22 January 2018 at 11:46, James Foster <smallt...@jgfoster.net> wrote:

> Since ‘atMax:’ doesn’t seem as clear to me, I’d prefer ‘upToMax:’ or
> ‘withMax:’ or (especially) the following:
>
> upTo: anInteger timesDo: aBlock
> upTo: anInteger timesSelect: aBlock
> upTo: anInteger timesCollect: aBlock
>
> James Foster
>
> > On Jan 21, 2018, at 8:56 AM, Stephane Ducasse <stepharo.s...@gmail.com>
> wrote:
> >
> > I thought about something like that...
> >
> > SequenceableCollection >> atMax: numberOfItems do: aBlock
> >    "Execute the iteration with at the maximum numberOfItems. If the
> > receiver contains less than numberOfItems iterate them all."
> >    1 to: (numberOfItems min: self size) do: [:index | aBlock value:
> > (self at: index)]
> >
> > This is an abstraction that we need to treat some samples.
> >
> > Stef
> >
> > On Sun, Jan 21, 2018 at 5:47 PM, Stephane Ducasse
> > <stepharo.s...@gmail.com> wrote:
> >> Hi Ben and Clement
> >>
> >> I have a collection (a dictionary in my case) and I want to get
> >> maximum 5 bindings out of it and iterate on them.
> >> I want keysAndValuesDo: or do: but only up to 5 elements.
> >>
> >> aDict atMax: 5 do: [:each | ]
> >>
> >> So I learned from:to:do:
> >>
> >> aCollection atMax: 5 do: [:each | ]
> >>
> >> Does it make sense?
> >>
> >> Stef
> >>
> >> On Sun, Jan 21, 2018 at 1:16 PM, Clément Bera <bera.clem...@gmail.com>
> wrote:
> >>> I don't think we do. Do you need it on SequenceableCollection or
> >>> HashedCollection too ?
> >>>
> >>> Recently I was trying to iterate over the first N elements of a
> collection
> >>> and since there was no #first:do: I used #from:to:do:. I guess you
> could use
> >>> that too:
> >>>
> >>> aCollection from: 1 to: (aCollection size min: 1000) do: aBlock
> >>>
> >>> Which guarantees you iterate at max over 1000 elements. But that API is
> >>> SequenceableCollection specific.
> >>>
> >>> On Sun, Jan 21, 2018 at 11:44 AM, Ben Coman <b...@openinworld.com>
> wrote:
> >>>>
> >>>> On 21 January 2018 at 18:36, Stephane Ducasse <
> stepharo.s...@gmail.com>
> >>>> wrote:
> >>>>> Hi
> >>>>>
> >>>>> I would like to iterate at max on a certain amount of elements in a
> >>>>> collection.
> >>>>> And I was wondering if we have such iterator.
> >>>>
> >>>> I'm not clear what functionality your asking for.  Could you present
> >>>> it as code & result if you assumed the iterator you want was
> >>>> available?
> >>>>
> >>>> cheers -ben
> >>>>
> >>>
> >>>
> >>>
> >>> --
> >>> Clément Béra
> >>> Pharo consortium engineer
> >>> https://clementbera.wordpress.com/
> >>> Bâtiment B 40, avenue Halley 59650 Villeneuve d'Ascq
> >
> >
>
>
>

Reply via email to