Skip to content

Commit

Permalink
feat: updating ToStringSliceE to support some other slices
Browse files Browse the repository at this point in the history
  • Loading branch information
sevennt authored and bep committed Jul 10, 2020
1 parent 1ffadf5 commit 580a25a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,12 @@ func TestToStringSliceE(t *testing.T) {
expect []string
iserr bool
}{
{[]int{1, 2}, []string{"1", "2"}, false},
{[]int8{int8(1), int8(2)}, []string{"1", "2"}, false},
{[]int32{int32(1), int32(2)}, []string{"1", "2"}, false},
{[]int64{int64(1), int64(2)}, []string{"1", "2"}, false},
{[]float32{float32(1.01), float32(2.01)}, []string{"1.01", "2.01"}, false},
{[]float64{float64(1.01), float64(2.01)}, []string{"1.01", "2.01"}, false},
{[]string{"a", "b"}, []string{"a", "b"}, false},
{[]interface{}{1, 3}, []string{"1", "3"}, false},
{interface{}(1), []string{"1"}, false},
Expand Down
30 changes: 30 additions & 0 deletions caste.go
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,36 @@ func ToStringSliceE(i interface{}) ([]string, error) {
return a, nil
case []string:
return v, nil
case []int8:
for _, u := range v {
a = append(a, ToString(u))
}
return a, nil
case []int:
for _, u := range v {
a = append(a, ToString(u))
}
return a, nil
case []int32:
for _, u := range v {
a = append(a, ToString(u))
}
return a, nil
case []int64:
for _, u := range v {
a = append(a, ToString(u))
}
return a, nil
case []float32:
for _, u := range v {
a = append(a, ToString(u))
}
return a, nil
case []float64:
for _, u := range v {
a = append(a, ToString(u))
}
return a, nil
case string:
return strings.Fields(v), nil
case interface{}:
Expand Down

0 comments on commit 580a25a

Please sign in to comment.