I propose adding ToSliceX helper functions to the cast package for converting values into slices of numeric types (e.g. []int, []int64, []float64).
Proposed API
ToIntSlice(i interface{}) []int
ToIntSliceE(i interface{}) ([]int, error)
ToInt64Slice(i interface{}) []int64
ToFloat64Slice(i interface{}) []float64
/* other functions */
These functions would convert common inputs like []interface{}, []string, or already-typed slices.
Benefits
- Reduces boilerplate
- Improves consistency with existing
cast APIs
- Makes numeric slice handling simpler and safer
Contribution
I’m happy to implement this feature, including tests and documentation, if the maintainers agree with the approach.
I propose adding
ToSliceXhelper functions to thecastpackage for converting values into slices of numeric types (e.g.[]int,[]int64,[]float64).Proposed API
These functions would convert common inputs like
[]interface{},[]string, or already-typed slices.Benefits
castAPIsContribution
I’m happy to implement this feature, including tests and documentation, if the maintainers agree with the approach.