lodash for Go

github.com/malcolmston/lodash

Type-safe, lodash-style functional utilities for Go.

 GitHubports lodash/lodash

A comprehensive, type-safe functional utility library for Go, inspired by JavaScript's lodash and built entirely on the standard library and Go 1.24 generics — no third-party dependencies, no cgo, no reflection on hot paths. Roughly 98 helpers span collections and slices (Map/Filter/Reduce/GroupBy/Uniq/Chunk/Difference/Union/SortBy), math (Sum/Mean/Min/Max/Clamp/Range), objects and nested maps (Keys/Pick/Omit/Invert/Merge/Get), string casing (CamelCase/SnakeCase/KebabCase/Deburr) and function wrappers (Once/Memoize/Debouncer/Throttler). Every function is pure and non-mutating unless documented otherwise: helpers return new slices or maps rather than modifying their arguments. Any randomness is injected through a *math/rand.Rand, so Sample, SampleN and Shuffle stay fully deterministic and testable, while Debouncer and Throttler take injectable timers and clocks. The import path is github.com/malcolmston/lodash and the package is named lodash.

Install

shell
$ go get github.com/malcolmston/lodash

Quick start

main.go
import lodash "github.com/malcolmston/lodash"

nums := []int{1, 2, 3, 4, 5, 6}
evens := lodash.Filter(nums, func(n int) bool { return n%2 == 0 })
doubled := lodash.Map(evens, func(n int) int { return n * 2 })
total := lodash.Sum(doubled) // 24

lodash.CamelCase("Foo Bar-baz") // "fooBarBaz"
lodash.SnakeCase("fooBarBaz")   // "foo_bar_baz"

Features

  • Collections — Map, Filter, Reduce, GroupBy, KeyBy, CountBy, Partition, ForEach
  • Querying — Find, FindIndex, Every, Some, Includes, IndexOf, LastIndexOf
  • Set & shape ops — Uniq, UniqBy, Chunk, Flatten, FlattenDeep, Difference, Intersection, Union, Zip, Unzip
  • Ordering & slicing — SortBy, OrderBy, Reverse, Take, TakeRight, Drop, DropRight
  • Randomness (seeded) — Sample, SampleN, Shuffle over an injected *math/rand.Rand
  • Math & numbers — Sum, SumBy, Mean, Min, Max, Clamp, Range, RangeStep, InRange
  • Objects & maps — Keys, Values, Entries, Pick, Omit, MapKeys, MapValues, Invert, Merge, Assign
  • Nested access — Get and Has resolve dot-separated paths into map[string]any trees
  • String casing — CamelCase, PascalCase, SnakeCase, KebabCase, StartCase, Capitalize, Deburr
  • String shaping — Words, Pad, PadStart, PadEnd, Truncate, Repeat, Trim
  • Function wrappers — Once, Memoize, MemoizeBy, After, Before
  • Rate control — NewDebouncer (Debouncer) and NewThrottler (Throttler) with injectable timers and clocks
  • Type-safe via Go 1.24 generics — no reflection on hot paths, no interface{} juggling at call sites
  • Zero dependencies — pure Go standard library, nothing to audit but the toolchain
lodash