function Y=mapcols(f,X)
% mapcols - Map a function of a vector over the columns of an array
%
% mapcols :: 
%    ([[N]->A] -> [[M]->B]) ~'function maps a column of A to one of B',
%    [[N,L]->A]
% -> [[M,L]->B].

n=size(X,2);
if n==0, Y=[];
else
	y1=f(X(:,1)); 
	if size(y1,2)>1
		Y=repmat(y1(:),1,n);
		for i=2:n
			Y(:,i)=flatten(f(flatten(X(:,i))));
		end
	else
		Y=repmat(y1,1,n);
		for i=2:n, Y(:,i)=f(X(:,i)); end
	end
end

