From e869e6c9bd4d9830d729c0c80203d77190b04493 Mon Sep 17 00:00:00 2001 From: Leon Mika Date: Tue, 27 May 2025 21:09:48 +1000 Subject: [PATCH] Added HashObject --- ucl/objs.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ucl/objs.go b/ucl/objs.go index f5894f1..0ec03b1 100644 --- a/ucl/objs.go +++ b/ucl/objs.go @@ -98,6 +98,33 @@ func (ss StringListObject) Index(i int) Object { return StringObject(ss[i]) } +type HashObject map[string]Object + +func (ho HashObject) String() string { + return fmt.Sprintf("%v", ho) +} + +func (ho HashObject) Truthy() bool { + return len(ho) > 0 +} + +func (ho HashObject) Len() int { + return len(ho) +} + +func (ho HashObject) Value(k string) Object { + return ho[k] +} + +func (ho HashObject) Each(fn func(k string, v Object) error) error { + for k, v := range ho { + if err := fn(k, v); err != nil { + return err + } + } + return nil +} + type iteratorObject struct { Iterable }