diff general/cellutils/cfold.m @ 44:3cedfd4549ef

Code added since initial check in.
author samer
date Tue, 13 Jan 2015 14:03:17 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/general/cellutils/cfold.m	Tue Jan 13 14:03:17 2015 +0000
@@ -0,0 +1,10 @@
+function X=cfold(fn,x)
+% fold - Fold combinator for cells
+%
+% fold :: (X,X->X), cells(A) -> X.
+%
+% This function applies an associative operator to a list of arguments,
+% as if the list was written out with the operator between consecutive
+% elements, eg fold(@plus,{1,2,3,4}) = 1+2+3+4.
+
+if isempty(x), X={}; else X=cfoldl(fn,head(x),next(x)); end