2007-08-27

Splitting a Cross-product in Mathematica

In Mathematica, the following expression will split a relational cross-product back into its component parts (assuming that common keys are sorted together):

SplitCrossProduct[keys_, list_] :=
  {
    #[[1, keys]],
    #[[Complement[Range[1, Length[list]], keys]]] & /@ #
  }& /@ Split[list, SameQ[#1[[keys]], #2[[keys]]] &]