Guide · Open source
How to use lo: Lodash-style helpers for Go slices and maps
Updated · written with AI from the project's own documentation and checked against our catalogue data
samber/lo is a Go library of small helper functions for working with slices, maps, strings, channels and functions, modeled loosely on JavaScript's Lodash. This guide shows you how to install it, import it, and use common helpers such as Map, Filter, Uniq and GroupBy. By the end you will know when it fits your Go code and when the standard library is a better choice.
Quick start
- 1Check your Go version. Confirm you have Go 1.18 or newer installed, since lo depends on generics.
- 2Add the library. In your module directory, run go get github.com/samber/lo@v1.
- 3Import the package. Add github.com/samber/lo to the import block of the Go file where you need it.
- 4Call a helper. Use a function such as lo.Uniq, passing your slice or map and using the returned value.
- 5Browse the docs. Look up exact helper signatures in the GoDoc or at lo.samber.dev/docs/about.
What you need before installing lo
lo requires Go 1.18 or newer because it is built on Go generics. Older Go versions will not compile it.
The library has no dependencies outside the Go standard library, so the only thing you add to your project is lo itself.
- Go 1.18 or newer installed
- A Go module for your project
Install lo with go get
Run the install command from the README in your project directory. The README pins the v1 line of the library, which follows SemVer strictly.
- No breaking changes to exported APIs will be made before v2.0.0, except in experimental packages under exp/.
go get github.com/samber/lo@v1Import lo into your code
Import the main package as shown below. The README also lists the parallel, mutable and it sub-packages for other use cases.
The README notes a shortcut that imports the whole library into your namespace, but it recommends against it, so the examples here use the lo. prefix.
- github.com/samber/lo: the main helpers
- github.com/samber/lo/parallel, github.com/samber/lo/mutable, github.com/samber/lo/it: additional packages
import (
"github.com/samber/lo"
)Use your first helper: Uniq
Helpers take a Go slice or map and return a new value, so you call them like normal functions. Uniq removes duplicate values from a slice.
The README example passes a slice with a repeated name and gets back each name once, in order of first appearance.
names := lo.Uniq([]string{"Samuel", "John", "Samuel"})
// []string{"Samuel", "John"}Common helpers for slices, maps and search
The README groups helpers by type. For slices, you will often use Map, Filter, Reduce, GroupBy and Chunk. For maps, Keys, Values and PickBy are common. For search, Contains, Find and First cover many simple loops.
Each helper is listed with its own anchor in the README spec and in the documentation at lo.samber.dev, where you can check exact signatures.
- Filter, Map, FlatMap, Reduce for slice transforms
- GroupBy and KeyBy for grouping and indexing
- Keys, Values, PickBy, OmitBy for maps
- Contains, Find, Some, Every for checks and searches
- Chunk, Flatten, Concat for reshaping data
Know the limits before you adopt lo
The README says 5 to 10 helpers overlap with the Go standard library slices and maps packages. If you only want the standard library, you may not need this dependency.
lo is for finite sequences processed synchronously. For infinite or event-driven data, the README points to the sibling project samber/ro.
- Not suitable for Go versions older than 1.18
- Overlaps with the standard slices and maps packages
- Not for infinite or event-driven streams; see samber/ro
What people use it for
- Removing duplicate IDs or names from a slice with Uniq
- Filtering and transforming records with Filter and Map instead of writing loops
- Grouping items by a field with GroupBy
- Pulling keys or values from a map with Keys and Values
- Splitting a large slice into batches with Chunk
Frequently asked questions
Is lo free to use?
lo is released under the MIT licence, as listed on its repository. You can use it in open-source and commercial Go projects under the terms of that licence.
What Go version does lo need?
The README states lo needs Go 1.18 or newer, because it is based on Go generics. Projects on older Go versions cannot use it.
How do I install lo?
Run go get github.com/samber/lo@v1 in your Go module directory. The library has no dependencies outside the standard library.
Does lo overlap with the standard library?
Yes. The README says 5 to 10 helpers may overlap with the slices and maps packages in the Go standard library. If you prefer only the standard library, you may not need lo.
Is lo similar to Lodash?
lo is a Lodash-style library and may look like Lodash in some aspects, with helpers such as Map, Filter and Uniq. It is a Go library, so it is typed with generics rather than being a JavaScript package.
Can lo handle infinite data streams?
No. The README says lo works on finite sequences synchronously. For infinite or event-driven data, it points to the sibling project samber/ro.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
lo suits Go developers who often transform slices or maps and want type-safe helpers instead of repeated loops, especially if they already know Lodash. If you must support Go older than 1.18, want only the standard library, or work with event-driven streams, pick the standard slices and maps packages or samber/ro instead.
Install options & downloads