What absolutely blew my mind when I started learning Go

Saurabh Kishore Tiwari
The Thought Mill
1 min readMay 19, 2024

--

When I started learning Go, I thought it’s interesting and simple. But then I got to know this one thing it just blew my mind…

Go supports only 3 data structures
1. Arrays
2. Slices
3. Maps

You can create a set using Maps, where Key can be whatever you want it to be and Value can be boolean.
But that’s it.

I was solving this question from LeetCode

My solution was a simple java solution, where I’m putting all the ListNodes into PriorityQueue and popping them out one by one and getting my answer.

A similar GO solution was present and it felt like too much work for something so obvious.

Coming from a Scala/Java background, I’m so used to PriorityQueue, ArrayList, HashSet, TreeMap, TreeSet and other such things while solving competitive coding questions that I almost feel helpless.

I tried digging deep to understand why aren’t there implementations for data structures commonly available in other languages. Turns out GO did not have support for generics and that sort of restricted the developers from creating a collections library.

Generics was introduced in Go 1.18 (March 2022).

There are talks going on as to when will we have standard collection library. But god knows when will it become a reality.

--

--