annotate sequences/@seq/foldl.m @ 3:3f77126f7b5f
First major revision of sequence library, now using classdef form, STILL A BIT BROKEN!
author |
samer |
date |
Wed, 09 Jan 2013 22:22:21 +0000 |
parents |
|
children |
03694e5c8365 |
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@3
|
13 if nargin<4,
|
samer@3
|
14 x=e;
|
samer@3
|
15 while ~isempty(y)
|
samer@3
|
16 x=fn(x,head(y));
|
samer@3
|
17 y=next(y);
|
samer@3
|
18 end
|
samer@3
|
19 else
|
samer@3
|
20 opts=prefs('quiet',1,varargin{:});
|
samer@3
|
21 x=e;
|
samer@3
|
22 while ~isempty(y)
|
samer@3
|
23 x=fn(x,head(y));
|
samer@3
|
24 y=next(y);
|
samer@3
|
25 if ~opts.quiet, fprintf('.'); end
|
samer@3
|
26 optpause(opts);
|
samer@3
|
27 end
|
samer@3
|
28 end
|