function X=fold(fn,args)
% fold - Fold combinator from functional programming
%
% This function applies an associative operator to a list of arguments,
% as if the list was written out with the operator between consecutive
% elements, eg fold(@plus,{1,2,3,4}) = 1+2+3+4.
%
% fold :: 
%    (X,X->X)	~'associative binary operator',
%    {[N]->X} ~'list (cell array) of arguments (at least 2 elements)'
% -> X.

if isempty(args), X=[]; else X=foldl(fn,args{1},args(2:end)); end
