chickadee » generalized-arrays » interleave-array

interleave-array arrayprocedure
reverse-interleave-array arrayprocedure

Transducer that interleaves the contents of the provided array into the transduction. reverse-interleave-array works similar to interleave-array, but interleaves the array onto the transduction in reverse-lexicographic ordering.

 
(import generalized-arrays
        transducers
        test)

(define a
  (make-array-from-storage vector-storage-class
                           (vector 3 3)
                           (vector 'a 'b 'c
                                   'd 'e 'f
                                   'g 'h 'i)))

(test "Interleave array to transduction"
      (list 1 'a 2 'b 3 'c)
      (transduce list-fold
                 (interleave-array a)
                 (collect-list)
                 (list 1 2 3))))

(test "Reverse zip array to transduction"
      (list 1 'i 2 'h 3 'g)
      (transduce list-fold
                 (reverse-interleave-array a)
                 (collect-list)
                 (list 1 2 3)))