% cacher- Cache each buffer to speed up multiple reads
%
% cacher :: 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.
classdef cacher < seq
	properties (GetAccess=private, SetAccess=private)
		source
		x
	end
	methods
		function o=cacher(source), o.source=source; o.x=head(source); end
		function x=head(o), x=o.x; end
		function s=tostring(o), s=['cache(',tostring(o.source),')']; end
		function z=elsize(o), z=size(o.x); end
		function o=next(o) 
			o.source=next(o.source); 
			if ~isempty(o.source), o.x=head(o.source); else o=o.source; end
		end
	end
end
