Generics code generation tool
How can we not write all that repetitive code and not take a performance hit, nor lose any type safety of our strongly-typed language?
Let's look at using Go tooling to generate the boilerplate code for us. We'll use it to replace interface{}
 in our code with <T>
. Here, <T>
represents any type that works in the context in which it is found.Â
Since we'll be using real types, we'll get compile-time type safety.
The clipperhouse/gen tool
Though there are several generics code generation tools available, let's look at my personal favorite, clipperhouse/gen.
We get the following functions for free with the clipperhouse/gen tool:
Aggregation | Filter | Map | Misc |
Note
gen
is a code-generation tool for Go. It's intended to offer generics-like functionality for your types. Out of the box, it offers LINQ/underscore-inspired...