On 23. 8. 2019 19:23, Herby Vojčík wrote:> On 23. 8. 2019 16:14, Julien
wrote:
>> Hello,
>>
>> I wanted to have an iterator framework for Pharo for a long time.
>>
>> So I started building it step by step and today I think that, while it
>> still requires more documentation, it is ready to be announced and
>> used by others.
>>
>> I present you Iterators : https://github.com/juliendelplanque/Iterators
>>
>> The idea is that, as described by the iterator design pattern, any
>> object that needs to be walked provides one or many iterators.
>>
>> In the library, #iterator method is the convention to get the default
>> iterator of any object (if it has one).
>>
>> Iterators provides a DSL to deal with iterators combination.
>>
>> It is inspired from shell’s streams manipulation syntax:
>>
>> - The pipe "|" allows one to chain iterators
>> - The ">" allows one to create a new collection with data transformed
>> through chained iterators
>> - The ">>" allows one to fill an existing collection with data
>> transformed through chained iterators
>> For example, one can write:
>>
>> iterator := #(1 2 3) iterator.
>> iterator
>> | [ :x | x * 2 ] collectIt
>> | [ :x :y | x + y ] reduceIt
>> > Array "#(12)"
>
> Isn't this something readStream should provide?
>
> str := #(1 2 3) readStream.
> str
> | [ :x | x * 2 ] collectIt
> | [ :x :y | x + y ] reduceIt
> > Array "#(12)"
>
> It is an object from which you take the front element, one at a time.
>
> Why have something very similar with different name?
>
> Herby
Now that I think about it, the problem may be a nomenclature.
This is my understanding, fix me if I am mistaken:
There are pull-based and push-based sequences out there. In Smalltalk it
can be said a sequence is pull-based if it has #next and #atEnd; it is
push-based if it has #do:.
AFAICT the tools to read pull-based sequence is called an iterator, and
it can have transformations like filter, map etc., sometimes called
"ix". The approach to transform push-based sequence (called observable)
is called reactive programming ("rx").
It seems you create rx-like library, but called the object iterator.
Maybe the set of operations you provide should be define for both
push-based and pull-based sequences, and called names that conform to
common canon.
Herby