chickadee » srfi-214 » flexvector-unfold

flexvector-unfold p f g initial-seed ...procedure

The fundamental flexvector constructor. flexvector-unfold is modeled on SRFI 1 unfold instead of SRFI 133 vector-unfold because flexvectors are not limited to a predetermined length. For each step, flexvector-unfold evaluates p on the seed value(s) to determine whether it should stop unfolding. If p returns #f, it then evaluates f on the seed value(s) to produce the next element, then evaluates g on the seed value(s) to produce the seed value(s) for the next step. The recursion can be described with this algorithm: This is guaranteed to build a flexvector in O(n) if flexvector-add-back! is O(1). flexvector-unfold-right is a variant that constructs a flexvector right-to-left, and uses flexvector-add-front! instead, which may be slower than O(n).