Persistent Vectors
(require alexis/pvector) | package: alexis-pvector |
This provides an implementation of persistent, immutable vectors. They are implemented as 32-way bitmapped tries with a tail to provide truly constant time appends to the end of the vector. Data is shared between a vector and its subsequent functional modifications.
The persistent vectors provided by this module implement the gen:equal+hash generic interface, so they may be used as keys, and equal? will perform deep comparisons. Additionally, they implement three interfaces from alexis/collection, gen:countable, gen:collection, and gen:sequence, which contain the interface for interacting with them.
1 Example Usage
Persistent vectors may be created using the pvector constructor.
> (pvector 1 2 3 4) #pv[1 2 3 4]
Afterwards, they can be interacted with via the functions from alexis/collection.
> (conj (pvector 1 2 3 4) 5) #pv[1 2 3 4 5]
It is often useful to create an empty vector using (pvector), then extending it with some other sequence.
> (extend (pvector) (take 10 (in-naturals))) #pv[0 1 2 3 4 5 6 7 8 9]
2 Native API Reference
The interface provided by alexis/pvector is small. Most of the functions for manipulating persistent vectors reside in alexis/collection. However, some functions are specific to persistent vectors.
3 Comprehensions
syntax
(for/pvector (for-clause ...) body-or-break ... body)
syntax
(for*/pvector (for-clause ...) body-or-break ... body)