init commit

This commit is contained in:
2025-11-01 15:01:22 -09:00
commit 143b17a6c1
8 changed files with 315 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
package vector
import (
"mal-go/utils"
"strings"
)
// TODO: replace COW with proper HashArrayMappedTrie impelmentation of PersistentVector
type Vector struct {
_slice []any
}
func New() *Vector {
return new(Vector).Init()
}
func (this *Vector) Init() *Vector {
this._slice = make([]any, 0)
return this
}
func Conj(this *Vector, data any) *Vector {
newVec := New()
for _, el := range this._slice {
newVec._slice = append(newVec._slice, el)
}
newVec._slice = append(newVec._slice, data)
return newVec
}
func (this *Vector) Conj(data any) *Vector {
return Conj(this, data)
}
func String(this *Vector) string {
if this == nil {
return "[]"
}
var sb strings.Builder
sb.WriteRune('[')
for _, el := range this._slice {
sb.WriteString(utils.Stringify(el))
sb.WriteRune(' ')
}
return sb.String()[:sb.Len()-1] + "]"
}
func (this *Vector) String() string {
return String(this)
}