Get the latest tech news

Generic interfaces


Adding type parameters to interface types is surprisingly powerful

And the use of a function field makes it harder for the compiler to inline the comparison calls, which can introduce a significant runtime overhead. Defining an interface for the set operations you require can add flexibility to your package, leaving the decision of what tradeoffs are right for the specific application to the user: This complicates things for callers slightly, but it has another advantage over the constraint to pointer receivers: remember that we started with a map[E]bool as a simple set type.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Generic Interfaces

Generic Interfaces