diff options
-rw-r--r-- | chickadee/array-list.scm | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/chickadee/array-list.scm b/chickadee/array-list.scm index 3b11ec1..5e2174c 100644 --- a/chickadee/array-list.scm +++ b/chickadee/array-list.scm @@ -30,7 +30,8 @@ array-list-push! array-list-pop! array-list-clear! - array-list-for-each)) + array-list-for-each + array-list-fold)) (define-record-type <array-list> (%make-array-list vector size) @@ -116,3 +117,12 @@ (when (< i size) (proc i (vector-ref vec i)) (loop (1+ i)))))) + +(define (array-list-fold proc init array-list) + (let ((size (array-list-size array-list)) + (vec (array-list-vector array-list))) + (let loop ((i 0) + (prev init)) + (if (< i size) + (loop (1+ i) (proc i (vector-ref vec i) prev)) + prev)))) |