A little FP goes a long way
A common complaint that people have against Go is that it encourages imperative programming over functional or object-oriented. Loops are perhaps the biggest offender. While Go's for
loops are very versatile, they're also a common site of out-of-bounds errors and other bugs.
Swapping out most of those for
loops with Map
and Filter
can make code far more reliable.
ns := []int{3, 5, 6, 9} squared := g_.Map(ns, func(n int) int { return n * n }) // [9 25 36 81]
Godash is modeled off of the popular JavaScript library Lodash, providing tools for working with Go slices and maps.
How it's made
Godash is written in pure Go 1.18, and has no dependencies. Go 1.18 introduced generics, which are what made these utilities possible.
Go's generics are a bit less flexible than in some languages however. A lot of the utils that Lodash offers simply aren't possible in a type-safe way with Go.
Try it for yourself
The library is available on Github here.