Feature: ToSlice
Open
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 4k
- Forks
- 337
- Avg merge
- 15m
- Merged PRs (30d)
- 1
Description
The current scope of application for the ToSlice method is too narrow, failing to cover many scenarios—for example:
type Users []User
ToSlice([]any{1,2,3,}) => []any{1, 2, 3}
ToSlice([]int{1,2,3,}) => []any{} // should []any{1,2,3}
ToSlice([]User{u1, u2}) => []any{} // should []any{u1, u2}
A possible new implementation:
func ToSliceE(v any) ([]any, error) {
if v == nil {
return nil, fmt.Errorf("nil")
}
rv := reflect.ValueOf(v)
if rv.Kind() != reflect.Slice && rv.Kind() != reflect.Array {
return nil, fmt.Errorf("not slice/array: %T", v)
}
out := make([]any, rv.Len())
for i := 0; i < rv.Len(); i++ {
out[i] = rv.Index(i).Interface()
}
return out, nil
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing ToSlice implementation and its related tests, then compare their current behavior for []any, []int, and named []User slices or arrays. Done means supported slice and array values are converted into []any with all elements preserved, with tests covering the examples in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 67/100