From c456a5ab97c9199319dd543ec600e3c86f8f7430 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Thu, 6 Mar 2025 16:55:09 -0500 Subject: [PATCH] lang: types: Add some length methods for list and map --- lang/types/value.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lang/types/value.go b/lang/types/value.go index 64b21247..3c5892e9 100644 --- a/lang/types/value.go +++ b/lang/types/value.go @@ -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?