sigildocs

(sigil array)

(sigil array) - Array Utilities

Higher-order functions for working with Sigil's dynamic arrays. For basic array operations (array, array-ref, array-set!, array-length, array-push, array-slice), use the prelude.

(import (sigil array))

(array-map (lambda (x) (* x 2)) #[1 2 3])  ; => #[2 4 6]
(array-filter odd? #[1 2 3 4 5])           ; => #[1 3 5]
(array-fold + 0 #[1 2 3 4 5])              ; => 15

Exports

make-arrayprocedure

Create an array of the given size, optionally filled with a value.

(make-array 5)        ; => #[#f #f #f #f #f]
(make-array 3 0)      ; => #[0 0 0]
(make-array 4 'x)     ; => #[x x x x]
array-copyprocedure

Create a copy of an array.

(define a #[1 2 3])
(define b (array-copy a))
(array-set! b 0 99)
a  ; => #[1 2 3] (unchanged)
b  ; => #[99 2 3]
array-mapprocedure

Apply a function to each element of an array, returning a new array.

(array-map (lambda (x) (* x 2)) #[1 2 3])
; => #[2 4 6]

Apply a procedure to each element of an array for side effects.

(array-for-each display #[1 2 3])
; prints: 123
array-foldprocedure

Fold a function over an array from left to right.

(array-fold + 0 #[1 2 3 4 5])
; => 15
array-filterprocedure

Return a new array containing only elements that satisfy the predicate.

(array-filter odd? #[1 2 3 4 5])
; => #[1 3 5]
array-findprocedure

Find the first element satisfying the predicate, or #f if none.

(array-find even? #[1 3 4 5])
; => 4
array-indexprocedure

Find the index of the first element satisfying the predicate, or #f.

(array-index even? #[1 3 4 5])
; => 2
array-every?procedure

Check if all elements satisfy the predicate.

(array-every? positive? #[1 2 3])
; => #t
array-any?procedure

Check if any element satisfies the predicate.

(array-any? even? #[1 3 4 5])
; => #t