2 ms·
Here's one way you could do the clipping generically in Go[1]. This has a Clip function that uses a type assertion. Another (perhaps better) implementation woul
by infogulch 11y ago
Here's one way you could do the clipping generically in Go[1]. This has a Clip function that uses a type assertion. Another (perhaps better) implementation would add Clip methods to both Rect and Poly.
Either way, I don't think this example proves the necessity of generics. Some algorithms are certainly more difficult to express in Go (graph data structures/algorithms in particular in my personal experience).
[1]: https://play.golang.org/p/xYQWDS41A0 https://play.golang.org/p/xYQWDS41A0
- pcwalton 11y ago> Here's one way you could do the clipping generically in Go[1]. This has a Clip function that uses a type assertion. Well, sure. But the title of the article is "Avoiding Reflection in Go". :)