lang: types: Add some length methods for list and map

This commit is contained in:
James Shubin
2025-03-06 16:55:09 -05:00
parent b5ae96e0d4
commit c456a5ab97

View File

@@ -927,6 +927,11 @@ func (obj *ListValue) List() []Value {
return obj.V
}
// Len returns the number of elements in this list.
func (obj *ListValue) Len() int {
return len(obj.V)
}
// Add adds an element to this list. It errors if the type does not match.
func (obj *ListValue) Add(v Value) error {
if obj.T.Val.Kind != KindVariant { // skip cmp if dest is a variant
@@ -1059,6 +1064,11 @@ func (obj *MapValue) Map() map[Value]Value {
return obj.V
}
// Len returns the number of elements in this map.
func (obj *MapValue) Len() int {
return len(obj.V)
}
// Add adds an element to this map. It errors if the types do not match.
func (obj *MapValue) Add(k, v Value) error { // TODO: change method name?