The fold operators foldl and foldr both take a binary operator, identifier or function R as the first argument followed by an argument I and an arbitrary number of arguments a, b, c, …, like for example foldl(R,I,a,b,c,...).
The left-fold operator foldl composes a binary operator R with initial value I onto the arguments a, b, …(which may be zero in number), associating from the left. For example, input :
Output :
The right-fold operator foldr is similar but associates operands from the right. For example, input :
Output :