function o=cache(source)
% CACHE- Cache each buffer to speed up multiple reads
%
% cache :: seq A -> seq A.
%
% The idea is that the data is cached on each call to NEXT,
% so that reading the array does not require calls to source.

if nargin==0, o=cache(0);
elseif isa(source,'cache'), o=source;
else
	ft.datafn=@datafn;
	ft.stringfn=@stringfn;
	ft.nextfn=@cachenext;
	o.x=head(source);
	o=class(o,'cache',ddata(source,size(source),ft));
end

function x=datafn(o), x=o.x;
function s=stringfn(o), s='cache';
function o=cachenext(o)
	o=next_c(o);
	if ~isempty(o), o.x=head(source(o)); end
	

