Get the latest tech news

Writing generic collection types in Go: the missing documentation


How to write a generic collection type in Go: 2 wrong ways and the right way.

As an aside, because enumerating explicit types without methods is common, a little bit of syntactic sugar allows us to omit the enclosing interface{}, leading to the compact and more idiomatic I've omitted everything but the type definitions and constructor funcs in the snippet above, but you can find the entire working implementation, along with a main method that tests it, here. The real lesson here, for me: when something seems like it should be possible in a programming language, but you can't find any working examples anywhere, it's time to suck it up and read the specification.

Get the Android app

Or read this on Hacker News