samber/lo
Lodash-style generic utility library for Go, leveraging Go 1.18+ generics. Provides map, filter, reduce, contains, find, uniq, group by, zip, chunk, and 100+ collection utilities without code generation or reflection. Fills the gap left by Go's minimal standard library for collection manipulation.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Pure utility library — no network access, no security concerns.
⚡ Reliability
Best When
Writing Go code that manipulates slices and maps where boilerplate loops obscure intent.
Avoid When
Go 1.17 or earlier, performance-critical code, or simple cases where a range loop is clearer.
Use Cases
- • Filter, map, and reduce Go slices without writing boilerplate loops: lo.Filter(items, func(x T, _ int) bool { return x.Active })
- • Find unique elements, group by key, or chunk slices: lo.Uniq(slice), lo.GroupBy(items, keyFn), lo.Chunk(items, 3)
- • Safely access maps without panic: lo.ValueOr(myMap, key, defaultValue) instead of map[key] with zero-value handling
- • Transform Go slices in data pipelines with type-safe generics instead of interface{} reflection approaches
- • Use lo.Must() and lo.Must2() for panic-on-error patterns in init code where error handling is verbose
Not For
- • Complex stream processing — lo is for in-memory slice/map operations, not streaming data
- • Go versions before 1.18 — lo requires generics support
- • Performance-critical hot paths — lo functions have some overhead vs hand-written loops for very large data
Interface
Authentication
Library — no auth needed.
Pricing
MIT licensed open source library.
Agent Metadata
Known Gotchas
- ⚠ lo.Must() and lo.Must2() panic on error — use only in init code or when errors are truly impossible; use lo.TryX() or explicit error handling in production
- ⚠ lo.Map() function signature requires both value and index parameters even if index is unused: func(x T, i int) R — use _ for unused index
- ⚠ lo.Filter() preserves order and returns a new slice — does not mutate the original slice
- ⚠ Generic type inference may fail for complex types — provide explicit type parameters: lo.Map[InputType, OutputType]() if inference fails
- ⚠ lo.Ternary() is not lazy — both branches are evaluated: lo.Ternary(cond, expensiveFn(), defaultFn()) evaluates both; use if/else for lazy evaluation
- ⚠ lo.Contains() uses == comparison — works for comparable types (primitives, structs with comparable fields) but not for slices or maps
Alternatives
Full Evaluation Report
Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for samber/lo.
AI-powered analysis · PDF + markdown · Delivered within 30 minutes
Package Brief
Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.
Delivered within 10 minutes
Score Monitoring
Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.
Continuous monitoring
Scores are editorial opinions as of 2026-03-07.