function d=subsampdata(a,b,varargin)
% subsampdata - Use arbitrary function to test and filter elements of another sequence
%
% subsampdata :: 
%	 natural		~ sample rate, 
%	 data(A),	~ source data,
%   ...    	~ options) 
%	-> data(A).
%
% Options
%	'datafn'::   	Data A->A	~ override function to get data
% 	'stringfn'::	Data A->String	~ override conversion to string
%	'nextfn'::  	Data A->(Data A | []) ~ override next function
%
% Methods
%
%   source :: filterdata(A) -> data(A).

if nargin==0, a=subsampdata(1,singleton(0)); end
if isa(a,'subsampdata'), d=a;
else
	d.n=a; 	
		
	opts=prefs('datafn',@datafn,'stringfn',@stringfn,'sizecheck',0,varargin{:});
	opts.nextfn=@nextfn;
	d=class(d,'subsampdata',ddata(b,size(b),opts));
end

function x=datafn(d), x=head(source(d));
function s=stringfn(d), s=sprintf('subsamp(%d)',tostring(d.n));
function o=nextfn(o)
	for i=1:o.n
		o=next_c(o);
		if isempty(o), break; end
	end

	
	
