[LRUG] Comparable Null Objects

Andrew Premdas apremdas at gmail.com
Fri Jul 17 06:18:45 PDT 2015


The use of a NullDate is not incompatible with something wanting to sort
Events in a particular way. If we think about how NullDate's should be
sorted we can see a very limited number of possibilities

- place at the end
- place at the beggining

So our NullDate could support a convention when implementing comparable to
make one of these choices and perhaps allow configuration to choose the
other. This would allow Events (and lots of other stuff) to use NullDates,
and allow Event collections to control how Date's effect the ordering.

I wonder should this functionality actually be in Date?

On 17 July 2015 at 11:51, James Mead <james at floehopper.org> wrote:

> I just came across the undocumented Date::Infinity class [1] which
> might be of some relevance to this thread.
>
> [1]:
> https://github.com/ruby/ruby/blob/c8b3f1b470e343e7408ab5883f046b1056d94ccc/ext/date/lib/date.rb#L7..L58
>
> On 17 July 2015 at 00:53, Paul Makepeace <paulm at paulm.com> wrote:
> > On Thu, Jul 16, 2015 at 3:24 PM, Stephen Best <bestie at gmail.com> wrote:
> >>
> >> events.sort_by { |e|
> >>   e.date { heat_death_of_the_universe }
> >> }
> >>
> >
> > This to me is the clearest of the proposals (Tom's role idea is cool
> too).
> >
> > For a null object you could also use... nil
> >
> >   events.sort_by { |e|
> >     e.date || date_that_sorts_at_the_end  # (named to be clearer about
> intent)
> >   }
> >
> > The whole discussion has been really interesting!
> >
> > Paul
> > _______________________________________________
> > Chat mailing list
> > Chat at lists.lrug.org
> > Archives: http://lists.lrug.org/pipermail/chat-lrug.org
> > Manage your subscription:
> http://lists.lrug.org/options.cgi/chat-lrug.org
> > List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> Archives: http://lists.lrug.org/pipermail/chat-lrug.org
> Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org
> List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>



-- 
------------------------
Andrew Premdas
blog.andrew.premdas.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20150717/9612e7a7/attachment-0003.html>


More information about the Chat mailing list