No generics in Golang, but...
Everyone knows that Go is a great language but that it does not support generics (yet?).
However in a language that supports first-class functions, generic types can be very handy. Fortunately, the gen package helps to fill this gap. Gen is a kind of macro tool that generate new structs from your models, with collections-like functions to filter, sort, group, iterate over your data.
You just need to add a
+gen annotation comment on your models :
Then, after running
go get github.com/clipperhouse/gen, you will be able to generate some Go code with the
Finally, the new generated types can be used as follow, for example to filter a list of messages :
It only remains to integrate the generation step in your build tool.