Has someone ever built a "sort block generator"

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

Has someone ever built a "sort block generator"

Mariano Martinez Peck
Hi guys,

Currently I have some sorting blocks which support "nil" elements (making them go first). 
So here is a general nil tolerant sort block based on one field:

defaultNilTolerantSortBlock: aBlock
[ :a :b | 
ifNil: [ true ]
ifNotNil: [ b 
ifNil: [ false ]
ifNotNil: [ 
aBlock value: a value: b
]  ]
]


Now...imagine that now I want to first on element1, then over element2...and both could be nil...in which case should go "first".

Anyway...does someone ever built some tool where you pass an ordered set of closures and it builds the super ugly resulting sort block?

Cheers, 

--
Mariano
http://marianopeck.wordpress.com
Reply | Threaded
Open this post in threaded view
|

Re: Has someone ever built a "sort block generator"

stepharo
Hi mariano

what are you doing? because it looks strange to need a sort block generator :).
Why cann't filter all the objects that have either fields to nil first?
Stef

On 31/7/14 19:40, Mariano Martinez Peck wrote:
Hi guys,

Currently I have some sorting blocks which support "nil" elements (making them go first). 
So here is a general nil tolerant sort block based on one field:

defaultNilTolerantSortBlock: aBlock
[ :a :b | 
ifNil: [ true ]
ifNotNil: [ b 
ifNil: [ false ]
ifNotNil: [ 
aBlock value: a value: b
]  ]
]


Now...imagine that now I want to first on element1, then over element2...and both could be nil...in which case should go "first".

Anyway...does someone ever built some tool where you pass an ordered set of closures and it builds the super ugly resulting sort block?

Cheers, 

--
Mariano
http://marianopeck.wordpress.com

Reply | Threaded
Open this post in threaded view
|

Re: Has someone ever built a "sort block generator"

Damien Cassou
On Thu, Jul 31, 2014 at 10:50 PM, stepharo <[hidden email]> wrote:
> what are you doing?


I think Mariano would like something like this:

persons sorted: #(lastname firstname birthdate) asSortBlock

that would sort by lastname, and if lastnames are equal by firstnames
and if both lastnames and firstnames are equal by birthdate.

--
Damien Cassou
http://damiencassou.seasidehosting.st

"Success is the ability to go from one failure to another without
losing enthusiasm."
Winston Churchill

Reply | Threaded
Open this post in threaded view
|

Re: Has someone ever built a "sort block generator"

Esteban A. Maringolo
Y asked for the same thing a few days ago in http://forum.world.st/Multiple-sorting-helper-td4770613.html

Something like:
sorter := MultipleSortCriteria new 
               add: #lastName; 
               add: [:each | each personalInfo age ] ascending: false. 
aCollection asSortedCollection: sorter. 


you could add something like:
sorter := MultipleSortCriteria new 
               add: #lastName; 
               add: #firstName ascending: false nullsFirst: true. 
aCollection asSortedCollection: sorter. 

Regards!


Esteban A. Maringolo


2014-08-01 2:40 GMT-03:00 Damien Cassou <[hidden email]>:
On Thu, Jul 31, 2014 at 10:50 PM, stepharo <[hidden email]> wrote:
> what are you doing?


I think Mariano would like something like this:

persons sorted: #(lastname firstname birthdate) asSortBlock

that would sort by lastname, and if lastnames are equal by firstnames
and if both lastnames and firstnames are equal by birthdate.

--
Damien Cassou
http://damiencassou.seasidehosting.st

"Success is the ability to go from one failure to another without
losing enthusiasm."
Winston Churchill


Reply | Threaded
Open this post in threaded view
|

Re: Has someone ever built a "sort block generator"

Mariano Martinez Peck



On Fri, Aug 1, 2014 at 11:31 AM, Esteban A. Maringolo <[hidden email]> wrote:
Y asked for the same thing a few days ago in http://forum.world.st/Multiple-sorting-helper-td4770613.html

Something like:
sorter := MultipleSortCriteria new 
               add: #lastName; 
               add: [:each | each personalInfo age ] ascending: false. 
aCollection asSortedCollection: sorter. 


Exactly!!!  
And... what is most important for me, is that to the MultipleSortCriteria I would like to ask #sortBlock :)

Thanks Esteban for better explaining what I was looking for ;)
 

you could add something like:
sorter := MultipleSortCriteria new 
               add: #lastName; 
               add: #firstName ascending: false nullsFirst: true. 
aCollection asSortedCollection: sorter. 

Regards!


Esteban A. Maringolo


2014-08-01 2:40 GMT-03:00 Damien Cassou <[hidden email]>:

On Thu, Jul 31, 2014 at 10:50 PM, stepharo <[hidden email]> wrote:
> what are you doing?


I think Mariano would like something like this:

persons sorted: #(lastname firstname birthdate) asSortBlock

that would sort by lastname, and if lastnames are equal by firstnames
and if both lastnames and firstnames are equal by birthdate.

--
Damien Cassou
http://damiencassou.seasidehosting.st

"Success is the ability to go from one failure to another without
losing enthusiasm."
Winston Churchill





--
Mariano
http://marianopeck.wordpress.com
Reply | Threaded
Open this post in threaded view
|

Re: Has someone ever built a "sort block generator"

Henrik Sperre Johansen

On 01 Aug 2014, at 4:47 , Mariano Martinez Peck <[hidden email]> wrote:




On Fri, Aug 1, 2014 at 11:31 AM, Esteban A. Maringolo <[hidden email]> wrote:
Y asked for the same thing a few days ago in http://forum.world.st/Multiple-sorting-helper-td4770613.html

Something like:
sorter := MultipleSortCriteria new 
               add: #lastName; 
               add: [:each | each personalInfo age ] ascending: false. 
aCollection asSortedCollection: sorter. 


Exactly!!!  
And... what is most important for me, is that to the MultipleSortCriteria I would like to ask #sortBlock :)

Thanks Esteban for better explaining what I was looking for ;)

I always liked this approach:

Don’t think anyone’s ported it to Pharo yet though.

Cheers,
Henry

signature.asc (859 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Has someone ever built a "sort block generator"

philippeback
Grids, collections, and sorting/filtering + paging. And xls export.

I guess we all have this kind of need in Seaside apps (and/or datatables).

Maybe we could have a hangout about these things.

I use the MagritteReport thing with some Twitter Bootstrap additions for reports.

Is there any best practice article somewhere that you use as a reference for your designs?

Phil



On Friday, August 1, 2014, Henrik Johansen <[hidden email]> wrote:

On 01 Aug 2014, at 4:47 , Mariano Martinez Peck <<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;marianopeck@gmail.com&#39;);" target="_blank">marianopeck@...> wrote:




On Fri, Aug 1, 2014 at 11:31 AM, Esteban A. Maringolo <<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;emaringolo@gmail.com&#39;);" target="_blank">emaringolo@...> wrote:
Y asked for the same thing a few days ago in http://forum.world.st/Multiple-sorting-helper-td4770613.html

Something like:
sorter := MultipleSortCriteria new 
               add: #lastName; 
               add: [:each | each personalInfo age ] ascending: false. 
aCollection asSortedCollection: sorter. 


Exactly!!!  
And... what is most important for me, is that to the MultipleSortCriteria I would like to ask #sortBlock :)

Thanks Esteban for better explaining what I was looking for ;)

I always liked this approach:

Don’t think anyone’s ported it to Pharo yet though.

Cheers,
Henry


--
---
Philippe Back
Visible Performance Improvements
Mob: +32(0) 478 650 140 | Fax: +32 (0) 70 408 027
Blog: http://philippeback.be | Twitter: @philippeback

High Octane SPRL
rue cour Boisacq 101 | 1301 Bierges | Belgium

Pharo Consortium Member - http://consortium.pharo.org/
Featured on the Software Process and Measurement Cast - http://spamcast.libsyn.com
Sparx Systems Enterprise Architect and Ability Engineering EADocX Value Added Reseller
 


Reply | Threaded
Open this post in threaded view
|

Re: Has someone ever built a "sort block generator"

camille teruel
In reply to this post by Mariano Martinez Peck

On 1 août 2014, at 16:47, Mariano Martinez Peck <[hidden email]> wrote:




On Fri, Aug 1, 2014 at 11:31 AM, Esteban A. Maringolo <[hidden email]> wrote:
Y asked for the same thing a few days ago in http://forum.world.st/Multiple-sorting-helper-td4770613.html

Something like:
sorter := MultipleSortCriteria new 
               add: #lastName; 
               add: [:each | each personalInfo age ] ascending: false. 
aCollection asSortedCollection: sorter. 


Exactly!!!  
And... what is most important for me, is that to the MultipleSortCriteria I would like to ask #sortBlock :)

To sort a collection with such an object it only has to answer #value:value:, so is there a special reason you want to generate a block from it?
Because generating such blocks might be a bit cumbersome and the object already does the job, no?


Thanks Esteban for better explaining what I was looking for ;)
 

you could add something like:
sorter := MultipleSortCriteria new 
               add: #lastName; 
               add: #firstName ascending: false nullsFirst: true. 
aCollection asSortedCollection: sorter. 

Regards!


Esteban A. Maringolo


2014-08-01 2:40 GMT-03:00 Damien Cassou <[hidden email]>:

On Thu, Jul 31, 2014 at 10:50 PM, stepharo <[hidden email]> wrote:
> what are you doing?


I think Mariano would like something like this:

persons sorted: #(lastname firstname birthdate) asSortBlock

that would sort by lastname, and if lastnames are equal by firstnames
and if both lastnames and firstnames are equal by birthdate.

--
Damien Cassou
http://damiencassou.seasidehosting.st

"Success is the ability to go from one failure to another without
losing enthusiasm."
Winston Churchill





-- 
Mariano
http://marianopeck.wordpress.com

Reply | Threaded
Open this post in threaded view
|

Re: Has someone ever built a "sort block generator"

camille teruel
In reply to this post by Henrik Sperre Johansen

On 1 août 2014, at 16:50, Henrik Johansen <[hidden email]> wrote:


On 01 Aug 2014, at 4:47 , Mariano Martinez Peck <[hidden email]> wrote:




On Fri, Aug 1, 2014 at 11:31 AM, Esteban A. Maringolo <[hidden email]> wrote:
Y asked for the same thing a few days ago in http://forum.world.st/Multiple-sorting-helper-td4770613.html

Something like:
sorter := MultipleSortCriteria new 
               add: #lastName; 
               add: [:each | each personalInfo age ] ascending: false. 
aCollection asSortedCollection: sorter. 


Exactly!!!  
And... what is most important for me, is that to the MultipleSortCriteria I would like to ask #sortBlock :)

Thanks Esteban for better explaining what I was looking for ;)

I always liked this approach:

Don’t think anyone’s ported it to Pharo yet though.

Yes it looks cool! 
We can try to port it then


Cheers,
Henry

Reply | Threaded
Open this post in threaded view
|

Re: Has someone ever built a "sort block generator"

Nicolas Cellier
In reply to this post by Henrik Sperre Johansen



2014-08-01 16:50 GMT+02:00 Henrik Johansen <[hidden email]>:

On 01 Aug 2014, at 4:47 , Mariano Martinez Peck <[hidden email]> wrote:




On Fri, Aug 1, 2014 at 11:31 AM, Esteban A. Maringolo <[hidden email]> wrote:
Y asked for the same thing a few days ago in http://forum.world.st/Multiple-sorting-helper-td4770613.html

Something like:
sorter := MultipleSortCriteria new 
               add: #lastName; 
               add: [:each | each personalInfo age ] ascending: false. 
aCollection asSortedCollection: sorter. 


Exactly!!!  
And... what is most important for me, is that to the MultipleSortCriteria I would like to ask #sortBlock :)

Thanks Esteban for better explaining what I was looking for ;)

I always liked this approach:

Don’t think anyone’s ported it to Pharo yet though.

Cheers,
Henry

+1

Note that I have a public experimental port to Pharo in SmalltalkHub that I already announced once (in http://smalltalkhub.com/#!/~nice/NiceVMExperiments but I can't tell exactly the package name TagSortFunction or something like that, the web interface of SmalltalkHub is currently showing me a debugger with nil does not understand #data).
Yes, I know VM-experiments is not the right place for such package, but at the time I didn't find where to create a new project...

Since I got absolutely zero feedback after a long thread, I assumed it was not interesting anybody...
But my personal opinion differs: this should be included in each and every Smalltalk.


Reply | Threaded
Open this post in threaded view
|

Re: Has someone ever built a "sort block generator"

Eliot Miranda-2



On Aug 1, 2014, at 10:50 AM, Nicolas Cellier <[hidden email]> wrote:




2014-08-01 16:50 GMT+02:00 Henrik Johansen <[hidden email]>:

On 01 Aug 2014, at 4:47 , Mariano Martinez Peck <[hidden email]> wrote:




On Fri, Aug 1, 2014 at 11:31 AM, Esteban A. Maringolo <[hidden email]> wrote:
Y asked for the same thing a few days ago in http://forum.world.st/Multiple-sorting-helper-td4770613.html

Something like:
sorter := MultipleSortCriteria new 
               add: #lastName; 
               add: [:each | each personalInfo age ] ascending: false. 
aCollection asSortedCollection: sorter. 


Exactly!!!  
And... what is most important for me, is that to the MultipleSortCriteria I would like to ask #sortBlock :)

Thanks Esteban for better explaining what I was looking for ;)

I always liked this approach:

Don’t think anyone’s ported it to Pharo yet though.

Cheers,
Henry

+1

Note that I have a public experimental port to Pharo in SmalltalkHub that I already announced once (in http://smalltalkhub.com/#!/~nice/NiceVMExperiments but I can't tell exactly the package name TagSortFunction or something like that, the web interface of SmalltalkHub is currently showing me a debugger with nil does not understand #data).
Yes, I know VM-experiments is not the right place for such package, but at the time I didn't find where to create a new project...

Since I got absolutely zero feedback after a long thread, I assumed it was not interesting anybody...
But my personal opinion differs: this should be included in each and every Smalltalk.

+1

Aloha
Reply | Threaded
Open this post in threaded view
|

Re: Has someone ever built a "sort block generator"

NorbertHartl
In reply to this post by Henrik Sperre Johansen


Am 01.08.2014 um 16:50 schrieb Henrik Johansen <[hidden email]>:


On 01 Aug 2014, at 4:47 , Mariano Martinez Peck <[hidden email]> wrote:




On Fri, Aug 1, 2014 at 11:31 AM, Esteban A. Maringolo <[hidden email]> wrote:
Y asked for the same thing a few days ago in http://forum.world.st/Multiple-sorting-helper-td4770613.html

Something like:
sorter := MultipleSortCriteria new 
               add: #lastName; 
               add: [:each | each personalInfo age ] ascending: false. 
aCollection asSortedCollection: sorter. 


Exactly!!!  
And... what is most important for me, is that to the MultipleSortCriteria I would like to ask #sortBlock :)

Thanks Esteban for better explaining what I was looking for ;)

I always liked this approach:

+1

Norbert
Don’t think anyone’s ported it to Pharo yet though.

Cheers,
Henry
Reply | Threaded
Open this post in threaded view
|

Re: Has someone ever built a "sort block generator"

Esteban A. Maringolo
In reply to this post by Nicolas Cellier
Nicolas:

2014-08-01 17:50 GMT-03:00 Nicolas Cellier <[hidden email]>:

>> http://objology.blogspot.no/2010/11/tag-sortfunctions-redux.html
>>
>> Don’t think anyone’s ported it to Pharo yet though.
> +1
>
> Note that I have a public experimental port to Pharo in SmalltalkHub that I
> already announced once (in
> http://smalltalkhub.com/#!/~nice/NiceVMExperiments but I can't tell exactly
> the package name TagSortFunction or something like that, the web interface
> of SmalltalkHub is currently showing me a debugger with nil does not
> understand #data).
> Yes, I know VM-experiments is not the right place for such package, but at
> the time I didn't find where to create a new project...

I decided to embrace you initial port and also made some enhancements
to TAGSortFunctions.

I added the current features:
* Support of MAElementDescription conversion to SortFunction (in
addition to block and unary symbol support)
* Collation of nil elements, deciding whether to put nil at the end or
beginning of the result.
  (similar to the ORDER BY column [NULLS FIRST|LAST] semantics of SQL).

Unit tests for the above described features.

All the added features preserve the original behavior of the sort
functions, so nil collation must be "enabled" explicitly by sending
#undefinedFirst/#undefinedLast to the sort function, otherwise it will
fail if you attempt to compare an object with nil.

I would like to move this to a specific repository in STHub with its
own Metacello config (Magritte support is packaged separately).
Do you agree with this?

Regards!

Esteban A. Maringolo