[top][index]
search for:

fold(VisibleList,Function) -- apply binary operator repeatedly

Synopsis:

  • Function: fold -- apply binary operator repeatedly
  • Input:
  • an instance of class VisibleList.
  • an instance of class Function.
  • Output:
  • an instance of class VisibleList.
  • fold({xn,...,x1,x0},f) -- computes f(...f(x2,f(x1,x0))...)}.

    i1 : fold({a,b,c,d,e}, identity)

    o1 = (a, (b, (c, (d, e))))

    o1 : Sequence

    Code:

         -- ../../../Macaulay2/m2/fold.m2:19-21
         fold(VisibleList,Function) := VisibleList => (v,f) -> (
              if #v === 0 then error "expected a nonempty list";
              fold(drop(v,-1),v#-1,f))     

    [top][index]
    search for: