library to chain select:/collect:/ ... via cascade

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

library to chain select:/collect:/ ... via cascade

Peter Uhnak
Hi,

is there some library that will allow me to chain select:/collect:/... via cascade?

E.g.

#(12 7 'a' nil #(0)) query reject: #isNil; select: #isNumber; collect: #squared; select: #even?

The point is to not have to write billion parentheses when building a more complex query.

I imagine this would be pretty easy to write, but figured I ask first.

Thanks,
Peter
Reply | Threaded
Open this post in threaded view
|

Re: library to chain select:/collect:/ ... via cascade

hernanmd
Hi Peter,

Have a look at:

http://smalltalkhub.com/#!/~zeroflag/Chain

As an alternative you may try the Specification Pattern

http://smalltalkhub.com/#!/~MassimoNocentini/SpecificationPattern

Cheers,

Hernán



El mié., 17 oct. 2018 a las 4:14, Peter Uhnak (<[hidden email]>) escribió:

>
> Hi,
>
> is there some library that will allow me to chain select:/collect:/... via cascade?
>
> E.g.
>
> #(12 7 'a' nil #(0)) query reject: #isNil; select: #isNumber; collect: #squared; select: #even?
>
> The point is to not have to write billion parentheses when building a more complex query.
>
> I imagine this would be pretty easy to write, but figured I ask first.
>
> Thanks,
> Peter

Reply | Threaded
Open this post in threaded view
|

Re: library to chain select:/collect:/ ... via cascade

Julien Delplanque-2
In reply to this post by Peter Uhnak
I think this was the idea of Transducers as well.

Julien

---
Julien Delplanque
Doctorant à l’Université de Lille
Bâtiment B 40, Avenue Halley 59650 Villeneuve d'Ascq
Numéro de téléphone: +333 59 35 86 40

Le 17 oct. 2018 à 09:13, Peter Uhnak <[hidden email]> a écrit :

Hi,

is there some library that will allow me to chain select:/collect:/... via cascade?

E.g.

#(12 7 'a' nil #(0)) query reject: #isNil; select: #isNumber; collect: #squared; select: #even?

The point is to not have to write billion parentheses when building a more complex query.

I imagine this would be pretty easy to write, but figured I ask first.

Thanks,
Peter

Reply | Threaded
Open this post in threaded view
|

Re: library to chain select:/collect:/ ... via cascade

Steffen Märcker
Hi,

indeed, transducers provided a way to achieve this, e.g.

#(12 7 'a' nil #(0)) pipe
        filter: #notNil;
        filter: #isNumber;
        map: #squared;
        filter: #even;
        into: OrderedCollection.

But this feature is deprecated, as it was not that useful. The preferred  
way to do this is either:

#(12 7 'a' nil #(0))
        transduce: #notNil filter * #isNumber filter * squared map * #even filter
        reduce: Set accumulate.

or:

Set <~ #even filter
     <~ #squared map
     <~ #isNumber filter
     <~ #notNil filter
     <~ #(12 7 'a' nil #(0)).

The advantage of the transducer approach is that it decouples  
filtering/mapping/etc. from iteration and aggregation. This facilitates  
reuse and makes it trivial to provide all operations to new custom data  
types.

However, I didn't have time to finish the Pharo port of Transducers, yet.  
Hence, the a current version is available in Cincom's Public Store or  
(most current) directly from me only. But if you are interested and have a  
nice use case, I'd be happy to help out.

Best, Steffen


Am .10.2018, 08:45 Uhr, schrieb Julien <[hidden email]>:

> I think this was the idea of Transducers as well.
>
> Julien
>
> ---
> Julien Delplanque
> Doctorant à l’Université de Lille
> http://juliendelplanque.be/phd.html
> Equipe Rmod, Inria
> Bâtiment B 40, Avenue Halley 59650 Villeneuve d'Ascq
> Numéro de téléphone: +333 59 35 86 40
>
>> Le 17 oct. 2018 à 09:13, Peter Uhnak <[hidden email]> a écrit :
>>
>> Hi,
>>
>> is there some library that will allow me to chain select:/collect:/...  
>> via cascade?
>>
>> E.g.
>>
>> #(12 7 'a' nil #(0)) query reject: #isNil; select: #isNumber; collect:  
>> #squared; select: #even?
>>
>> The point is to not have to write billion parentheses when building a  
>> more complex query.
>>
>> I imagine this would be pretty easy to write, but figured I ask first.
>>
>> Thanks,
>> Peter

Reply | Threaded
Open this post in threaded view
|

Re: library to chain select:/collect:/ ... via cascade

Steffen Märcker
Another important difference is that no intermediate collections are  
built. In contrast, chaining x enumeration statements #select:, #collect:,  
etc. iterates x times over the collection elements and builds x-1  
intermediate collections.

Am .10.2018, 11:59 Uhr, schrieb Steffen Märcker <[hidden email]>:

> Hi,
>
> indeed, transducers provided a way to achieve this, e.g.
>
> #(12 7 'a' nil #(0)) pipe
> filter: #notNil;
> filter: #isNumber;
> map: #squared;
> filter: #even;
> into: OrderedCollection.
>
> But this feature is deprecated, as it was not that useful. The preferred  
> way to do this is either:
>
> #(12 7 'a' nil #(0))
> transduce: #notNil filter * #isNumber filter * squared map * #even  
> filter
> reduce: Set accumulate.
>
> or:
>
> Set <~ #even filter
>      <~ #squared map
>      <~ #isNumber filter
>      <~ #notNil filter
>      <~ #(12 7 'a' nil #(0)).
>
> The advantage of the transducer approach is that it decouples  
> filtering/mapping/etc. from iteration and aggregation. This facilitates  
> reuse and makes it trivial to provide all operations to new custom data  
> types.
>
> However, I didn't have time to finish the Pharo port of Transducers,  
> yet. Hence, the a current version is available in Cincom's Public Store  
> or (most current) directly from me only. But if you are interested and  
> have a nice use case, I'd be happy to help out.
>
> Best, Steffen
>
>
> Am .10.2018, 08:45 Uhr, schrieb Julien <[hidden email]>:
>
>> I think this was the idea of Transducers as well.
>>
>> Julien
>>
>> ---
>> Julien Delplanque
>> Doctorant à l’Université de Lille
>> http://juliendelplanque.be/phd.html
>> Equipe Rmod, Inria
>> Bâtiment B 40, Avenue Halley 59650 Villeneuve d'Ascq
>> Numéro de téléphone: +333 59 35 86 40
>>
<---Schnitt--->
>