view sequences/+seq/unfold.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents b1280319413e
children
line wrap: on
line source
% unfold - infinite sequence obtained by iterating unfolding function over state
%
% unfold :: 
%    (S->A,S)	~'unfolding function',
%    S         ~ initial state,
% -> seq(A).
classdef unfold < seq
	properties (GetAccess=private, SetAccess=immutable)
		fn
	end
	properties (GetAccess=private, SetAccess=private)
		value
		state
	end
	methods
		function d=unfold(f,s0,varargin)
			[x,s]=f(s0);
			d.value=x;
			d.state=s;
			d.fn=f; 	% function to apply 
		end

		function s=elsize(o), s=size(o.value); end
		function s=tostring(o), s=sprintf('unfold(%s,%s)',tostring(o.fn),tostring(o.state)); end
		function x=head(o), x=o.value; end
		function o=next(o), [o.value,o.state]=o.fn(o.state); end
	end
end