% forels - do an action for each element of an array in order
%
% forels :: 
%    (A->action) ~'action to apply to each element', 
%    [[Size]->A] ~'array of elements of type',
%    options iterate_options
% => void.
%
% Note, the array can be multidimensional - the standard order
% cycles through the earlier indices before the later ones, eg
% rows, then columns, then slices etc.

function forels(f,X,varargin)
	N=numel(X);
	iterate(@g,1,varargin{:});

	function i=g(i)
		if i>N, i=[]; else f(X(i)); i=i+1; end
	end
end
