From f8037a1f9991ad0dbe1120d91f5089a0e3355e9e Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 15 Oct 2024 20:53:39 -0400 Subject: [PATCH] lang: types: Add a small helper function for common type conversions --- lang/types/util.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lang/types/util.go b/lang/types/util.go index 32c33c9a..802a20b4 100644 --- a/lang/types/util.go +++ b/lang/types/util.go @@ -216,3 +216,16 @@ type UnifiedState struct { func (obj *UnifiedState) String(typ *Type) string { return typ.string(obj.table) } + +// ListStrToValue is a simple helper function to convert from a list of strings +// in golang to the equivalent in our type system. +func ListStrToValue(input []string) Value { + l := NewList(TypeListStr) + for _, x := range input { + v := &StrValue{ + V: x, + } + l.V = append(l.V, v) // be more efficient than using .Add(...) + } + return l +}