Mercurial > hg > ishara
diff general/cellutils/cfoldr.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 | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/general/cellutils/cfoldr.m Wed Jan 16 12:12:34 2013 +0000 @@ -0,0 +1,13 @@ +function X=foldr(fn,e,args) +% foldr - Fold from the right for cell arrays +% +% This function applies an operator to a list of arguments, +% starting from the right, eg +% elements, eg foldr(@plus,0,{1,2,3,4}) = (1+(2+(3+(4+0)))). +% +% foldr :: +% (Y,X->X) ~'associative binary operator', +% Y ~'initial element', +% {[N]->Y} ~'list (cell array) of arguments' +% -> Y. +X=e; for i=length(args):-1:1, X=fn(args{i},X); end