Lo
💥 A Lodash-style Go library based on Go 1.18+ Generics (map, filter, contains, find...)
Install / Use
/learn @samber/LoREADME
lo - Iterate over slices, maps, channels...
✨ samber/lo is a Lodash-style Go library based on Go 1.18+ Generics.
A utility library based on Go 1.18+ generics that makes it easier to work with slices, maps, strings, channels, and functions. It provides dozens of handy methods to simplify common coding tasks and improve code readability. It may look like Lodash in some aspects.
5 to 10 helpers may overlap with those from the Go standard library, in packages slices and maps. I feel this library is legitimate and offers many more valuable abstractions.
See also:
- samber/ro: Reactive Programming for Go: declarative and composable API for event-driven applications
- samber/do: A dependency injection toolkit based on Go 1.18+ Generics
- samber/mo: Monads based on Go 1.18+ Generics (Option, Result, Either...)
- samber/cc-skills-golang: AI Agent Skills for Golang
What makes it different from samber/ro?
- lo: synchronous helpers across finite sequences (maps, slices...)
- ro: processing of infinite data streams for event-driven scenarios
<div align="center"> <sup><b>💖 Sponsored by:</b></sup> <br> <a href="https://www.dbos.dev/?utm_campaign=gh-smbr"> <div> <img width="200" alt="dbos" src="https://github.com/user-attachments/assets/d583cb62-7735-4d3c-beb7-e6ef1a5faf49" /> </div> <div> DBOS - Durable workflow orchestration library for Go </div> </a> </div>
Why this name?
I wanted a short name, similar to "Lodash", and no Go package uses this name.

🚀 Install
go get github.com/samber/lo@v1
# AI Agent Skill
npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-lo
This library is v1 and follows SemVer strictly.
No breaking changes will be made to exported APIs before v2.0.0, except for experimental packages under exp/.
This library has no dependencies outside the Go standard library.
💡 Usage
You can import lo using:
import (
"github.com/samber/lo"
lop "github.com/samber/lo/parallel"
lom "github.com/samber/lo/mutable"
loi "github.com/samber/lo/it"
)
Then use one of the helpers below:
names := lo.Uniq([]string{"Samuel", "John", "Samuel"})
// []string{"Samuel", "John"}
Tips for lazy developers
I cannot recommend it, but in case you are too lazy for repeating lo. everywhere, you can import the entire library into the namespace.
import (
. "github.com/samber/lo"
)
I take no responsibility for this junk. 😁 💩
🤠 Spec
GoDoc: godoc.org/github.com/samber/lo
Documentation: lo.samber.dev
Supported helpers for slices:
- Filter
- Map
- UniqMap
- FilterMap
- FlatMap
- Reduce
- ReduceRight
- ForEach
- ForEachWhile
- Times
- Uniq
- UniqBy
- GroupBy
- GroupByMap
- Chunk
- Window
- Sliding
- PartitionBy
- Flatten
- Concat
- Interleave
- Shuffle
- Reverse
- Fill
- Repeat
- RepeatBy
- KeyBy
- SliceToMap / Associate
- FilterSliceToMap
- Keyify
- Take
- TakeWhile
- TakeFilter
- Drop
- DropRight
- DropWhile
- DropRightWhile
- DropByIndex
- Reject
- RejectMap
- FilterReject
- Count
- CountBy
- CountValues
- CountValuesBy
- Subset
- Slice
- Replace
- ReplaceAll
- Clone
- Compact
- IsSorted
- IsSortedBy
- Splice
- Cut
- CutPrefix
- CutSuffix
- Trim
- TrimLeft
- TrimPrefix
- TrimRight
- TrimSuffix
Supported helpers for maps:
- Keys
- UniqKeys
- HasKey
- ValueOr
- Values
- UniqValues
- PickBy
- PickByKeys
- PickByValues
- OmitBy
- OmitByKeys
- OmitByValues
- Entries / ToPairs
- FromEntries / FromPairs
- Invert
- Assign (merge of maps)
- ChunkEntries
- MapKeys
- MapValues
- MapEntries
- MapToSlice
- FilterMapToSlice
- FilterKeys
- FilterValues
Supported math helpers:
Supported helpers for strings:
- RandomString
- Substring
- ChunkString
- RuneLength
- PascalCase
- CamelCase
- KebabCase
- SnakeCase
- Words
- Capitalize
- Ellipsis
Supported helpers for tuples:
- T2 -> T9
- Unpack2 -> Unpack9
- Zip2 -> Zip9
- ZipBy2 -> ZipBy9
- Unzip2 -> Unzip9
- UnzipBy2 -> UnzipBy9
- CrossJoin2 -> CrossJoin2
- CrossJoinBy2 -> CrossJoinBy2
Supported helpers for time and duration:
Supported helpers for channels:
- ChannelDispatcher
- SliceToChannel
- ChannelToSlice
- Generator
- Buffer
- BufferWithContext
- BufferWithTimeout
- FanIn
- FanOut
Supported intersection helpers:
- Contains
- ContainsBy
- Every
- EveryBy
- Some
- SomeBy
- None
- NoneBy
- Intersect
- IntersectBy
- Difference
- Union
- Without
- WithoutBy
- WithoutEmpty
- WithoutNth
- ElementsMatch
- ElementsMatchBy
Supported search helpers:
- IndexOf
- LastIndexOf
- HasPrefix
- HasSuffix
- Find
- FindIndexOf
- FindLastIndexOf
- FindOrElse
- FindKey
- FindKeyBy
- FindUniques
- FindUniquesBy
- FindDuplicates
- FindDuplicatesBy
- Min
- MinIndex
- MinBy
- MinIndexBy
- Earliest
- EarliestBy
- Max
- MaxIndex
- MaxBy
- MaxIndexBy
- Latest
- LatestBy
- First
- FirstOrEmpty
- FirstOr
- Last
- LastOrEmpty
- LastOr
- Nth
- NthOr
- NthOrEmpty
- Sample
- SampleBy
- Samples
- SamplesBy
Conditional helpers:
Type manipulation helpers:
- IsNil
- IsNotNil
- ToPtr
- Nil
- EmptyableToPtr
- FromPtr
- FromPtrOr
- ToSlicePtr
- FromSlicePtr
- FromSlicePtrOr
- ToAnySlice
- FromAnySlice
- Empty
- IsEmpty
- IsNotEmpty
- Coalesce
- CoalesceOrEmpty
- CoalesceSlice
- CoalesceSliceOrEmpty
- CoalesceMap
- CoalesceMapOrEmpty
Function helpers:
Concurrency helpers:
