{"modulePath":"github.com/glojurelang/glojure","version":"v0.2.2","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package vector\n\nPackage vector implements persistent vector.\n\nThis is a Go clone of Clojure's PersistentVector type ([https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentVector.java](https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentVector.java)). For an introduction to the internals, see [https://hypirion.com/musings/understanding-persistent-vector-pt-1](https://hypirion.com/musings/understanding-persistent-vector-pt-1).\n\nThis code has been copied from the package \"src.elv.sh/pkg/persistent/vector\" with modifications for efficiency.\n\n## Types\n\n```go\ntype Iterator interface {\n\t// Elem returns the element at the current position.\n\tElem() interface{}\n\t// HasElem returns whether the iterator is pointing to an element.\n\tHasElem() bool\n\t// Next moves the iterator to the next position.\n\tNext()\n}\n```\nIterator is an iterator over vector elements. It can be used like this:\n\n\tfor it := v.Iterator(); it.HasElem(); it.Next() {\n\t    elem := it.Elem()\n\t    // do something with elem...\n\t}\n\n```go\ntype Transient struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewTransient(vi Vector) *Transient\n```\nNewTransient returns a new transient vector.\n\n```go\nfunc (t *Transient) Assoc(i int, val interface{}) *Transient\n```\n\n```go\nfunc (t *Transient) Conj(v interface{}) *Transient\n```\nConj adds an element to the end of the vector.\n\n```go\nfunc (t *Transient) Count() int\n```\n\n```go\nfunc (t *Transient) Index(i int) (any, bool)\n```\n\n```go\nfunc (t *Transient) Persistent() *vector\n```\npersistent returns a persistent vector from the transient vector.\n\n```go\nfunc (t *Transient) Pop() *Transient\n```\n\n```go\ntype Vector interface {\n\tjson.Marshaler\n\t// Len returns the length of the vector.\n\tLen() int\n\t// Index returns the i-th element of the vector, if it exists. The second\n\t// return value indicates whether the element exists.\n\tIndex(i int) (interface{}, bool)\n\t// Assoc returns an almost identical Vector, with the i-th element\n\t// replaced. If the index is smaller than 0 or greater than the length of\n\t// the vector, it returns nil. If the index is equal to the size of the\n\t// vector, it is equivalent to Conj.\n\tAssoc(i int, val interface{}) Vector\n\t// Conj returns an almost identical Vector, with an additional element\n\t// appended to the end.\n\tConj(val interface{}) Vector\n\t// Pop returns an almost identical Vector, with the last element removed. It\n\t// returns nil if the vector is already empty.\n\tPop() Vector\n\t// SubVector returns a subvector containing the elements from i up to but\n\t// not including j.\n\tSubVector(i, j int) Vector\n\t// Iterator returns an iterator over the vector.\n\tIterator() Iterator\n}\n```\nVector is a persistent sequential container for arbitrary values. It supports O(1) lookup by index, modification by index, and insertion and removal operations at the end. Being a persistent variant of the data structure, it is immutable, and provides O(1) operations to create modified versions of the vector that shares the underlying data structure, making it suitable for concurrent access. The empty value is a valid empty vector.\n\n```go\nvar Empty Vector = \u0026vector{}\n```\nEmpty is an empty Vector.\n\n```go\nfunc New(elems ...interface{}) Vector\n```\nNew returns a new Vector with the given elements.\n\n","path":"github.com/glojurelang/glojure/internal/persistent/vector","name":"vector","synopsis":"Package vector implements persistent vector.","isRedistributable":true}
