chickadee » transducers » collect-f32vector

collect-vector #!optional (size-hint 0)procedure
collect-u8vector #!optional (size-hint 0)procedure
collect-u16vector #!optional (size-hint 0)procedure
collect-u32vector #!optional (size-hint 0)procedure
collect-u64vector #!optional (size-hint 0)procedure
collect-s8vector #!optional (size-hint 0)procedure
collect-s16vector #!optional (size-hint 0)procedure
collect-s32vector #!optional (size-hint 0)procedure
collect-s64vector #!optional (size-hint 0)procedure
collect-f32vector #!optional (size-hint 0)procedure
collect-f64vector #!optional (size-hint 0)procedure
collect-c64vector #!optional (size-hint 0)procedure
collect-c128vector #!optional (size-hint 0)procedure

Collectors that incrementally aggregate items from the transduction into a vector by pushing elements into the vector in amortized O(1) time. A size-hint can be provided to pre-allocate the capacity of the accumulated vector.

In most instances these collectors are fast enough on their own that one should probably avoid using the size-hint without either a good amount of knowledge or benchmarks to suggest otherwise. No intermediate lists or other collections are used in order to do this collection.

 
(import transducers srfi-4)

(transduce u8vector-fold
           (map exact->inexact)
           (collect-f64vector)
           (u8vector 1 2 3 4 5 6 7 8))

; => #f64(1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0)