News for hackers. Stuff that matters.
Re:Go generics are not bad by nemothekid on Friday July 08, 2022 @06:47PM (#32028705)
I haven't looked into Go's actual implementation but isn't this kind of downcasted better suited for interfaces. Your code, as is, wouldn't translate to something like Rust which uses monomorphization; you are doing a runtime "inspection" of the types. This looks more in the domain of duck-typing than something that generics handles.
Re:Go generics are not bad by SekstiNi on Friday July 08, 2022 @06:51PM (#32028763)
Here's a writeup exploring this very topic, and showing how Go's generics will currently give worse performance than just using an interface.

https://planetscale.com/blog/generics-can-make-your-go-code-...