Re: [Pharo-users] looking for another iterator :)

2018-01-26 Thread Sean P. DeNigris
Evan Donahue wrote > It is also worth mentioning that there is now also the Cons library > available > through the Pharo6 catalog browser… just creates an iterator and never > actually creates the whole list…The code is stable and in use in several > of my projects. Very interesting! Thanks :)

Re: [Pharo-users] looking for another iterator :)

2018-01-26 Thread Steffen Märcker
Hi! No stress is good news! - what is the API in terms of vocabulary (ie drop the same as reject) These are the operations implemented so far. |= means "satisfies", i.e., evaluate to true. Drop drop first n elements DropWhile drop first elements |= a block Filter* pick

Re: [Pharo-users] looking for another iterator :)

2018-01-25 Thread Evan Donahue
It is also worth mentioning that there is now also the Cons library available through the Pharo6 catalog browser. Cons is a lazy linked list that can be used like a normal linked list, but can also be used as an iterator over streams or infinite-sequence-generating blocks, using the usual Pharo col

Re: [Pharo-users] looking for another iterator :)

2018-01-25 Thread Richard O'Keefe
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 (LimitedEn

Re: [Pharo-users] looking for another iterator :)

2018-01-25 Thread Richard O'Keefe
My own Smalltalk has these: Enumerable methods for: 'enumerating' limit: n do: aBlock "Pass elements of the receiver to aBlock one at a time, as for #do:, but stop after n elements. n must be a non-negative SmallInteger. Which elements you get is for the receiver

Re: [Pharo-users] looking for another iterator :)

2018-01-24 Thread Stephane Ducasse
I like the pharophile :) On Mon, Jan 22, 2018 at 10:57 AM, Sven Van Caekenberghe wrote: > yes, we need composition to avoid API explosion (things are already very bad > in this respect) > >> On 22 Jan 2018, at 10:38, Guillermo Polito wrote: >> >> In most collection libraries I know there is th

Re: [Pharo-users] looking for another iterator :)

2018-01-24 Thread Stephane Ducasse
On Mon, Jan 22, 2018 at 11:26 AM, Steffen Märcker wrote: > Hi! > > this is straightforward with Transducers, e.g., > >> (Take n: 5) <~ #(1 2 3 4 5 6 7 8). > > or >> >> #(1 2 3 4 5 6 7 8) transduce take: 5. > > > The different primitives like take, drop, map, filter, etc. are composable > and do no

Re: [Pharo-users] looking for another iterator :)

2018-01-24 Thread Esteban A. Maringolo
2018-01-22 6:57 GMT-03:00 Sven Van Caekenberghe : > yes, we need composition to avoid API explosion (things are already very bad > in this respect) And the names of the proposed selectors suggests it could be even worst. +1 to composition. Esteban A. Maringolo

Re: [Pharo-users] looking for another iterator :)

2018-01-22 Thread Steffen Märcker
Hi! this is straightforward with Transducers, e.g., (Take n: 5) <~ #(1 2 3 4 5 6 7 8). or #(1 2 3 4 5 6 7 8) transduce take: 5. The different primitives like take, drop, map, filter, etc. are composable and do not generate intermediate representations. The bad news are, that the Pharo por

Re: [Pharo-users] looking for another iterator :)

2018-01-22 Thread Sven Van Caekenberghe
yes, we need composition to avoid API explosion (things are already very bad in this respect) > On 22 Jan 2018, at 10:38, Guillermo Polito wrote: > > In most collection libraries I know there is the "take" function coming from > the functional world that does that: > > #(1 2 3 4 5 6 7 8) take

Re: [Pharo-users] looking for another iterator :)

2018-01-22 Thread Guillermo Polito
In most collection libraries I know there is the "take" function coming from the functional world that does that: #(1 2 3 4 5 6 7 8) take: 5 => #(1 2 3 4 5) #(1 2 3 4) take: 5 => #(1 2 3 4) Now, I understand there are two different things in here. - First is the fact that we would like to a

Re: [Pharo-users] looking for another iterator :)

2018-01-21 Thread Ben Coman
On 22 January 2018 at 00:47, Stephane Ducasse 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 | ] "atMax" s

Re: [Pharo-users] looking for another iterator :)

2018-01-21 Thread Richard Sargent
SomeCollection every: 5 do: [:subset | subset collect: [:each | ...]] etc. If you want the first five only, return from the do: block. Possibly, #every: by itself answers an iterator / collection conforming instance. On Jan 21, 2018 14:47, "James Foster" wrote: > Since ‘atMax:’ doesn’t seem as

Re: [Pharo-users] looking for another iterator :)

2018-01-21 Thread James Foster
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 wrote: > > I tho

Re: [Pharo-users] looking for another iterator :)

2018-01-21 Thread Ben Coman
On 22 January 2018 at 00:47, Stephane Ducasse 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 l

Re: [Pharo-users] looking for another iterator :)

2018-01-21 Thread Stephane Ducasse
Now an iterator getting atMax: x elements could be better because we could them combined it with collect:, detect:... Stef On Sun, Jan 21, 2018 at 5:56 PM, Stephane Ducasse wrote: > I thought about something like that... > > SequenceableCollection >> atMax: numberOfItems do: aBlock > "Execut

Re: [Pharo-users] looking for another iterator :)

2018-01-21 Thread Stephane Ducasse
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: (s

Re: [Pharo-users] looking for another iterator :)

2018-01-21 Thread Stephane Ducasse
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

Re: [Pharo-users] looking for another iterator :)

2018-01-21 Thread Clément Bera
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:

Re: [Pharo-users] looking for another iterator :)

2018-01-21 Thread Ben Coman
On 21 January 2018 at 18:36, Stephane Ducasse 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

[Pharo-users] looking for another iterator :)

2018-01-21 Thread Stephane Ducasse
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. Stef