nilTolerantSortBlock suggestion...

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

nilTolerantSortBlock suggestion...

Christopher J. Demers
I like multi-column list views and I like to be able to sort on the various
columns.  One problem I ran into was when some objects had a nil value in
one of the columns that would cause an error when they were sorted.  I got
around this issue by using a nil tolerant sort block (see bellow).  I added
this method to the SortedCollection class side to make it easy to refer to
it.  This block seems to handle any kind of object that responds to #<.

==========
SortedCollection class<<nilTolerantSortBlock

 "cdemers - 5/31/2002 This is a nil tolerant sort block, for use with sorted
collections
 that may contain nil values."

 ^[:a :b | (a isNil or: [b isNil])
  ifFalse: [a < b]
  ifTrue: [a isNil]]
==========

I notice that the SortedCollection class has a method that returns a case
sensitive sort block.  I wonder if a method to return a nil tolerant sort
block would perhaps be a useful addition to the system?  I have found this
to be very handy for column sort blocks.

Chris