annotate general/cellutils/@cell/foldr.m @ 13:03694e5c8365
Reorganised some high order list functions to correct class-based method dispatch; fixed some docs.
author |
samer |
date |
Wed, 16 Jan 2013 12:12:34 +0000 |
parents |
fbc0540a9208 |
children |
|
rev |
line source |
samer@12
|
1 function X=foldr(fn,e,args)
|
samer@12
|
2 % foldr - Fold combinator from functional programming
|
samer@12
|
3 %
|
samer@12
|
4 % This function applies an associative operator to a list of arguments,
|
samer@12
|
5 % starting from the right, eg
|
samer@12
|
6 % elements, eg foldr(@plus,0,{1,2,3,4}) = (1+(2+(3+(4+0)))).
|
samer@12
|
7 %
|
samer@12
|
8 % foldr ::
|
samer@12
|
9 % (Y,X->X) ~'associative binary operator',
|
samer@12
|
10 % Y ~'initial element',
|
samer@12
|
11 % {[N]->Y} ~'list (cell array) of arguments (at least 2 elements)'
|
samer@12
|
12 % -> Y.
|
samer@12
|
13 X=e; for i=length(args):-1:1, X=fn(args{i},X); end
|