Le 16 déc. 2014 22:48, "dboeren" <boer...@gmail.com> a écrit :.
> Off the top of my head, I would be interested in support for "slices"
> meaning taking being able to treat a subset of a larger OrderedCollection
as
> its own OrderedCollection rather than using copyFrom:to: to create a
> duplicate object to work with.  It seems to me that this would be a more
> efficient method and should not be difficult to implement I think.

Here is an email I sent about that :

I see you are working on new collections for Pharo. That's great news,
I'm convinced we can do much better (even if what we already have is
already much better than what can be found in most other languages).
One thing you could work on is the notion of iterator. There are
plenty of ways to iterate over a collection:

1/ from the first to the last item
2/ from the last to the first
3/ from the 2nd item to the 5th
4/ only even items (2, 4, 6, ...)
5/ ...

Currently, we have to create new collections to iterate in strange
ways. For example, to iterate from the last to the first item, we
create a new collection by sending #reversed to the original
collection. I think that is bad because it creates a copy and that
should not be necessary. What we miss is the notion of iterator. An
iterator is an object that is specialized in iterating over any kind
of collection and has methods like #select:, #reject:, #allSatisfy:.
>From a collection, you can access different kinds of iterators
(reusing the same ordering as before):

1/ aCollection iterator
2/ aCollection reverseIterator
3/ aCollection from: 2 to: 5
4/ aCollection iterator select: [ :each | each isEven ] --> that
returns an iterator as well, so you can call #select:/#reject:
multiple times without creating any intermediate collection
5/ ...

Lukas Renggli implemented a prototype that looks really nice but is
unfinished: http://source.lukas-renggli.ch/unsorted/Container-lr.7.mcz.

I think the notion of Sequences in Clojure is very related as well.
Sequence functions are very generic and can be applied to any kind of
collection. http://clojure.org/sequences

Reply via email to