Implement DistinctBy

First part of the fix for #284. This is all the hard work, but leaves the most interesting test
pending because it will require a second sort to be introduced in the compiler. That PR will 
be coming soon.
I think this is better than the old hack, but create a new ticket to track removing this from the AST.