Adding ToSlice
diff --git a/cast.go b/cast.go
index 4bd3ba3..dee6787 100644
--- a/cast.go
+++ b/cast.go
@@ -42,6 +42,11 @@
return v
}
+func ToSlice(i interface{}) []interface{} {
+ v, _ := ToSliceE(i)
+ return v
+}
+
func ToStringSlice(i interface{}) []string {
v, _ := ToStringSliceE(i)
return v
diff --git a/caste.go b/caste.go
index 78c9483..78c6a9e 100644
--- a/caste.go
+++ b/caste.go
@@ -179,6 +179,30 @@
return m, fmt.Errorf("Unable to Cast %#v to map[string]interface{}", i)
}
+func ToSliceE(i interface{}) ([]interface{}, error) {
+ jww.DEBUG.Println("ToSliceE called on type:", reflect.TypeOf(i))
+
+ var s []interface{}
+
+ switch v := i.(type) {
+ case []interface{}:
+ fmt.Println("here")
+ for _, u := range v {
+ s = append(s, u)
+ }
+ return s, nil
+ case []map[string]interface{}:
+ for _, u := range v {
+ s = append(s, u)
+ }
+ return s, nil
+ default:
+ return s, fmt.Errorf("Unable to Cast %#v of type %v to []interface{}", i, reflect.TypeOf(i))
+ }
+
+ return s, fmt.Errorf("Unable to Cast %#v to []interface{}", i)
+}
+
func ToStringSliceE(i interface{}) ([]string, error) {
jww.DEBUG.Println("ToStringSliceE called on type:", reflect.TypeOf(i))