function y=filter(a,b,x,z,dim)
% filter - filter for sequences of array
%
% filter :: [[P]], [[P]], seq [Size], [[P]], D:natural -> seq [Size].
% filter :: [[P]], [[P]], seq [Size], [[P]]  -> seq [Size].
% filter :: [[P]], [[P]], seq [Size]  -> seq [Size].
%
% filtering is done along Dth dimension of the array (default=1)

if isempty(x), y=nil; return; end
if nargin<5, 
	dim=find(size(x)>1,1);
	if isempty(dim), dim=1; end
	if nargin<4, z=[]; end
end

y = mapaccum(@(x1,z1)filter(a,b,x1,z1,dim),z,x);
