annotate sequences/@seq/foldl.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents beb8a3f4a345
children
rev   line source
samer@3 1 function x=foldl(fn,e,y,varargin)
samer@3 2 % foldl - Fold combinator for sequences
samer@3 3 %
samer@3 4 % This function applies an associative operator to a list of arguments,
samer@3 5 % starting from the left using the given starting element.
samer@3 6 %
samer@3 7 % foldl ::
samer@3 8 % (X,Y->X) ~'associative binary operator',
samer@3 9 % X ~'initial element',
samer@3 10 % seq(Y) ~'a lazy sequence'
samer@3 11 % -> X.
samer@3 12
samer@13 13 if iscell(y), x=cfoldl(fn,e,y); return; end
samer@3 14 if nargin<4,
samer@3 15 x=e;
samer@3 16 while ~isempty(y)
samer@3 17 x=fn(x,head(y));
samer@3 18 y=next(y);
samer@3 19 end
samer@3 20 else
samer@37 21 opts=options('quiet',1,varargin{:});
samer@3 22 x=e;
samer@3 23 while ~isempty(y)
samer@3 24 x=fn(x,head(y));
samer@3 25 y=next(y);
samer@3 26 if ~opts.quiet, fprintf('.'); end
samer@3 27 optpause(opts);
samer@3 28 end
samer@3 29 end