How can GatherBy be programmed to take an option to group results as follows:
data = {T0->1993-09-29,T1->1993-10-04,T10->1993-09-29,T11->1993-10-01,T12->1993-10-02,T13->1993-10-04,T14->1992-10,T3->1991,T4->1991,T7->1992-10,T8->1992-10,T9->1993-09-26}
Column@(data2 = GatherBy[data, #[[2]] & ]) gives:
{T0->1993-09-29,T10->1993-09-29}
{T1->1993-10-04,T13->1993-10-04}
{T11->1993-10-01}
{T12->1993-10-02}
{T14->1992-10,T7->1992-10,T8->1992-10}
{T3->1991,T4->1991}
{T9->1993-09-26}
It's desired to optionally group into lists based on the common right-hand sides:
Column[ ((First /@ #) -> #[[1, 2]]) & /@ data2], which gives:
{T0,T10}->1993-09-29
{T1,T13}->1993-10-04
{T11}->1993-10-01
{T12}->1993-10-02
{T14,T7,T8}->1992-10
{T3,T4}->1991
{T9}->1993-09-26
And to do this not just for Rule expression arguments but for any argument and GatherBy test functions.


gatherBy, and introduce any syntax you like. The essential part of your question can be answered similarly to what I did for your previous one, but I guess this type of solution is not what you are after. – Leonid Shifrin Jun 21 '12 at 19:58gatherBy[expr_,f_,postf_]:=Map[postf,GatherBy[expr,f]], for a start. You seem to want some postprocessing. – Leonid Shifrin Jun 21 '12 at 22:09