chickadee » generalized-arrays » reverse-array-fold

array-fold f sentinel xsprocedure
reverse-array-fold f sentinel xsprocedure

Transducer-aware folding operations over arrays. Every element in the array is folded in lexicographic order, starting at the default (zero) index of the array and ending at the maximum dimension of the array.

 
(import generalized-arrays
        transducers
        test)

(define a
  (make-array-from-storage vector-storage-class
                           (vector 3 3)
                           (vector 1 2 3
                                   4 5 6
                                   7 8 9)))

(test "Sum of all array values is 45"
      45
      (transduce array-fold
                 values
                 (collect-sum 0)
                 a)

array-reverse-fold works like array-fold, but folds over the array in reverse-lexicographic order, starting at the maximum dimension of the array and ending at the default (zero) index of the array.