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'll have to take a closer look. I'm not sure how the state is initialized, or what we get from the transformation.