Dependency or DIY

Since generics came out in Go, I have been using the github.com/samber/lo package for functional helpers for doing things. Best examples are lo.Map or lo.Ptr which are quite nice to use e.g.

// Instead of this
s := []int{1, 2, 3}
newSlice := make([]string, len(s))
for i := range s {
    newSlice[i] = strconv.Itoa(s[i])
}

// I can just do
s := []int{1, 2, 3}
newSlice := lo.Map(s, func(e int, _ int) string { return strconv.Itoa(e) })

It’s a lot more concise and quite easier to write.

The problem

Go also introduced new iterator types that are iter.Seq[T] or iter.Seq2[K, V] for maps.

They are actually quite great, but the issue is that I can’t use them with my favorite samber/lo functions. Go has not provided new functions for working with iterators, e.g. map, reduce, flatmap and such. (Not surprising honestly since it took them till version 1.18 to introduce strings.Cut and then 2 more versions to add strings.CutPrefix/Suffix)

And then there is also all the issues we have recently had with npm stuff being hacked, and made me think about our choices in dependencies.

I could always just write things like Map on my own, and never use another dependency for that, but downloading a bunch of such small functions is also a lot a bit faster and easier. But then at the same time doing just func Map<Tab> and have Supermaven or Cursor or whatever is your choice of AI assistant complete these things is soooo easy.

My only issue with doing this on my own is that I have to convince others in my team that it might be better to just write these helpers, rather than download them because everyone is used to the go get github.com/magic/solution that I don’t know if can be fixed that easily.