lang: types: Add a small helper function for common type conversions

This commit is contained in:
James Shubin
2024-10-15 20:53:39 -04:00
parent 067eef9007
commit f8037a1f99

View File

@@ -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
}