mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-26 03:30:09 -05:00
120 lines
2.6 KiB
Cheetah
120 lines
2.6 KiB
Cheetah
// {{.Name}}
|
|
|
|
type {{.Name}} struct {
|
|
l types.List
|
|
}
|
|
|
|
func New{{.Name}}() {{.Name}} {
|
|
return {{.Name}}{types.NewList()}
|
|
}
|
|
|
|
{{if .CanUseDef}}
|
|
type {{.Name}}Def []{{defType .ElemType}}
|
|
|
|
func (def {{.Name}}Def) New() {{.Name}} {
|
|
l := make([]types.Value, len(def))
|
|
for i, d := range def {
|
|
l[i] = {{defToValue "d" .ElemType }}
|
|
}
|
|
return {{.Name}}{types.NewList(l...)}
|
|
}
|
|
|
|
func (l {{.Name}}) Def() {{.Name}}Def {
|
|
d := make([]{{defType .ElemType}}, l.Len())
|
|
for i := uint64(0); i < l.Len(); i++ {
|
|
d[i] = {{valueToDef "l.l.Get(i)" .ElemType }}
|
|
}
|
|
return d
|
|
}
|
|
{{end}}
|
|
|
|
func {{.Name}}FromVal(val types.Value) {{.Name}} {
|
|
// TODO: Validate here
|
|
return {{.Name}}{val.(types.List)}
|
|
}
|
|
|
|
|
|
func (l {{.Name}}) NomsValue() types.Value {
|
|
return l.l
|
|
}
|
|
|
|
func (l {{.Name}}) Equals(p {{.Name}}) bool {
|
|
return l.l.Equals(p.l)
|
|
}
|
|
|
|
func (l {{.Name}}) Ref() ref.Ref {
|
|
return l.l.Ref()
|
|
}
|
|
|
|
func (l {{.Name}}) Len() uint64 {
|
|
return l.l.Len()
|
|
}
|
|
|
|
func (l {{.Name}}) Empty() bool {
|
|
return l.Len() == uint64(0)
|
|
}
|
|
|
|
func (l {{.Name}}) Get(i uint64) {{userType .ElemType}} {
|
|
return {{valueToUser "l.l.Get(i)" .ElemType}}
|
|
}
|
|
|
|
func (l {{.Name}}) Slice(idx uint64, end uint64) {{.Name}} {
|
|
return {{.Name}}{l.l.Slice(idx, end)}
|
|
}
|
|
|
|
func (l {{.Name}}) Set(i uint64, val {{userType .ElemType}}) {{.Name}} {
|
|
return {{.Name}}{l.l.Set(i, {{userToValue "val" .ElemType}})}
|
|
}
|
|
|
|
func (l {{.Name}}) Append(v ...{{userType .ElemType}}) {{.Name}} {
|
|
return {{.Name}}{l.l.Append(l.fromElemSlice(v)...)}
|
|
}
|
|
|
|
func (l {{.Name}}) Insert(idx uint64, v ...{{userType .ElemType}}) {{.Name}} {
|
|
return {{.Name}}{l.l.Insert(idx, l.fromElemSlice(v)...)}
|
|
}
|
|
|
|
func (l {{.Name}}) Remove(idx uint64, end uint64) {{.Name}} {
|
|
return {{.Name}}{l.l.Remove(idx, end)}
|
|
}
|
|
|
|
func (l {{.Name}}) RemoveAt(idx uint64) {{.Name}} {
|
|
return {{.Name}}{(l.l.RemoveAt(idx))}
|
|
}
|
|
|
|
func (l {{.Name}}) fromElemSlice(p []{{userType .ElemType}}) []types.Value {
|
|
r := make([]types.Value, len(p))
|
|
for i, v := range p {
|
|
r[i] = {{userToValue "v" .ElemType}}
|
|
}
|
|
return r
|
|
}
|
|
|
|
type {{.Name}}IterCallback func(v {{userType .ElemType}}) (stop bool)
|
|
|
|
func (l {{.Name}}) Iter(cb {{.Name}}IterCallback) {
|
|
l.l.Iter(func(v types.Value) bool {
|
|
return cb({{valueToUser "v" .ElemType}})
|
|
})
|
|
}
|
|
|
|
type {{.Name}}IterAllCallback func(v {{userType .ElemType}})
|
|
|
|
func (l {{.Name}}) IterAll(cb {{.Name}}IterAllCallback) {
|
|
l.l.IterAll(func(v types.Value) {
|
|
cb({{valueToUser "v" .ElemType}})
|
|
})
|
|
}
|
|
|
|
type {{.Name}}FilterCallback func(v {{userType .ElemType}}) (keep bool)
|
|
|
|
func (l {{.Name}}) Filter(cb {{.Name}}FilterCallback) {{.Name}} {
|
|
nl := New{{.Name}}()
|
|
l.IterAll(func(v {{userType .ElemType}}) {
|
|
if cb(v) {
|
|
nl = nl.Append(v)
|
|
}
|
|
})
|
|
return nl
|
|
}
|