-
Notifications
You must be signed in to change notification settings - Fork 18k
language: support explicit conversion from []A to []B if A is assignable to B #3756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
I don't feel comfortable with the idea to allow "conversion" of []non-interface to []interface. IMO, it's technically not a conversion when the result and source of the "conversion" are slices with different memory layouts. It's hidden code invoked by a conversion like syntax, which I don't like to see in Go. |
Thinking about alternatives, the following would work for my Join example: // Join joins the elements yielded by next using sep, formatting each element of a as %v would. func Join(sep string, next func() (interface{}, bool)) string times := []time.Time{ t1, t2, t3 } var i int s := Join(",", func() (interface{}, bool) { if i < len(times) { t := times[i] i++ return t, true } return nil, false }) Or, if we assume indexed access: func Join(sep string, at func(i int) (interface{}, bool)) string times := []time.Time{ t1, t2, t3 } s := Join(",", func(i int) (interface{}, bool) { if i < len(times) { return times[i], true } return nil, false }) This is probably more efficient than what I proposed in this issue, since it avoids allocating a new slice. |
I don't believe the conversion suggested here will happen, because it would hide an unbounded amount of allocation, while all current conversions are bounded. I will leave this open for someday if you think we should keep the conversation going. Labels changed: added priority-someday, languagechange, removed priority-triage. Status changed to LongTerm. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: