Wednesday, August 18, 2010

Spaceship operator

When making a sort closure, use the spaceship operator to allow for sorting where their might be nulls.
A more detailed explanation can be found here


// This does not work
[0, 1, null, 'a'].sort{a,b-> a > b}

// This sorts fine
[0, 1, null, 'a'].sort{a,b-> a <=> b}

No comments:

Post a Comment