diff options
Diffstat (limited to 'tuples.go')
-rw-r--r-- | tuples.go | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -144,7 +144,7 @@ func (e *Element) UnmarshalJSON(b []byte) (err error) { return } -// Mostly the same as Element{e}, but also converts any int or float type to an +// Mostly the same as Element{e}, but also converts any int/bool or float type to an // int64 or float64, respectively. // Throws a runtime panic if an unsupported type is given. // TODO: Also convert composite types into arrays/maps? @@ -153,7 +153,16 @@ func El(e interface{}) Element { // Core elements case nil, string, int64, float64, []Element, map[string]Element: return Element{v} + // Already an element + case Element: + return v // Conversions + case bool: + if v { + return Element{int64(1)} + } else { + return Element{int64(0)} + } case int: return Element{int64(v)} case int8: @@ -171,6 +180,9 @@ func El(e interface{}) Element { case uint32: return Element{int64(v)} case uint64: + if v > 1<<63-1 { + panic("Value out of range") + } return Element{int64(v)} case float32: return Element{float64(v)} |