[top][index]
search for:

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

Synopsis:

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

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

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

    o1 : Sequence
    i2 : fold(plus, {1,2,3,4,5})

    o2 = 15

    Code:

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

    [top][index]
    search for: