f::fold1 (public)

 f::fold1 f xs

Defined in packages/acs-tcl/tcl/ad-functional-procs.tcl

Takes a binary function f and a list {x1 x2 x3 ...} and returns (...(f (f (f x1 x2) x3) x4)...).

"fold1" behaves like "fold", but does not take a start element and does not work for empty lists.

Examples

  • fold1 min [list 3 1 4 1 5 9 2 6] = 1
  • fold1 max [list 3 1 4 1 5 9 2 6] = 9

Parameters:
f
xs

Partial Call Graph (max 5 caller/called nodes):
%3 f::lmax f::lmax (public) f::fold1 f::fold1 f::lmax->f::fold1 f::lmin f::lmin (public) f::lmin->f::fold1 f::fold f::fold (public) f::fold1->f::fold f::head f::head (public) f::fold1->f::head f::null_p f::null_p (public) f::fold1->f::null_p f::tail f::tail (public) f::fold1->f::tail

Testcases:
No testcase defined.
Source code:
    if { [null_p $xs] } {
        error "ERROR: fold1 is undefined for empty lists."
    } else {
        fold $f [head $xs] [tail $xs]
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: