“unique” in golang — you may not be knowing this

Kirubakaran
2 min readJust now

What is the unique feature of golang — its unique, yes you read it correctly🙂

It’s a new addition to the Go standard library as of Go 1.23, not many developers might be aware of it yet.

Interested in Cobra???

Image taken from here

This package helps you deduplicate comparable values like strings, integers, or even structs.

Why this is useful?

  • Efficiency: By canonicalizing values(Canonicalization is a process that converts data with multiple representations into a standard form.), you ensure only one copy exists in memory. Needless to say, this can certainly reduce memory usage and improve performance, especially when dealing with large datasets or frequently duplicated values.
  • Simplified Comparisons: When you know values are canonicalized, you can compare them just by checking their pointers instead of their content, leading to faster equality checks.

Think of it like interning strings, but applicable to various data types. It’s particularly useful when:

--

--

Kirubakaran

Software Engineer expertise on C, C++, Golang, Python, Docker, Kubernetes.