function y=groupby_or(f,x)
% groupby_or - collect rows of x into equivalence classes based f
%
% groupby_or :: ([[1,M]]->A), [[N,M]] -> {[K]->[[L,M]]} :- equality(A).
%
% IMPORTANT: this version assumes that data is ordered by f, that is,
% only consecutive rows will be grouped together.

	N=size(x,1);
	y={}; 
	
	i=1; j=1;
	while j<=N
		if i==j, z=f(x(i,:)); end
		if j==N || f(x(j+1,:)~=z)
			y=vertcat(y,{x(i:j,:)});
			i=j+1; j=i;
		else j=j+1; 
		end
	end

