Skip to content

Commit f91a334

Browse files
authored
Merge pull request #1161 from goplus/xgopilot/issue-1159-1768803255
feat: add NewValue and NewList initialization functions
2 parents 352237b + e7396da commit f91a334

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

list.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ func (p *Value) Set(v obj) {
191191
p.data = fromObj(v)
192192
}
193193

194+
// NewValue creates a new Value initialized with the given object.
195+
func NewValue(o obj) Value {
196+
return Value{data: fromObj(o)}
197+
}
198+
194199
// -------------------------------------------------------------------------------------
195200

196201
type List struct {
@@ -328,3 +333,12 @@ func (p *List) IndexOf(v obj) Pos {
328333
func (p *List) Clear() {
329334
p.data = p.data[:0]
330335
}
336+
337+
// NewList creates a new List initialized with the given elements.
338+
func NewList(l ...obj) List {
339+
data := make([]obj, len(l))
340+
for i, v := range l {
341+
data[i] = fromObj(v)
342+
}
343+
return List{data: data}
344+
}

0 commit comments

Comments
 (0)