skills/golang-samber-lo/SKILL.md
Functional programming helpers for Golang using samber/lo — 500+ type-safe generic functions for slices, maps, channels, strings, math, tuples, and concurrency (Map, Filter, Reduce, GroupBy, Chunk, Flatten, Find, Uniq, etc.). Core immutable package (lo), concurrent variants (lo/parallel aka lop), in-place mutations (lo/mutable aka lom), lazy iterators (lo/it aka loi for Go 1.23+), and experimental SIMD (lo/exp/simd). Apply when using or adopting samber/lo, when the codebase imports github.com/samber/lo, or when implementing functional-style data transformations in Go. Not for streaming pipelines (→ See `golang-samber-ro` skill).
npx skillsauth add rockcookies/skills golang-samber-loInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Persona: You are a Go engineer who prefers declarative collection transforms over manual loops. You reach for lo to eliminate boilerplate, but you know when the stdlib is enough and when to upgrade to lop, lom, or loi.
Lodash-inspired, generics-first utility library with 500+ type-safe helpers for slices, maps, strings, math, channels, tuples, and concurrency. Zero external dependencies. Immutable by default.
Official Resources:
This skill is not exhaustive. Please refer to library documentation and code examples for more information. Context7 can help as a discoverability platform.
Go's stdlib slices and maps packages cover ~10 basic helpers (sort, contains, keys). Everything else — Map, Filter, Reduce, GroupBy, Chunk, Flatten, Zip — requires manual for-loops. lo fills this gap:
interface{} casts, no reflection, compile-time checking, no interface boxing overheadlo, upgrade to lop/lom/loi only when profiling demands itErr suffixes (MapErr, FilterErr, ReduceErr) that stop on first errorgo get github.com/samber/lo
| Package | Import | Alias | Go version |
| --- | --- | --- | --- |
| Core (immutable) | github.com/samber/lo | lo | 1.18+ |
| Parallel | github.com/samber/lo/parallel | lop | 1.18+ |
| Mutable | github.com/samber/lo/mutable | lom | 1.18+ |
| Iterator | github.com/samber/lo/it | loi | 1.23+ |
| SIMD (experimental) | github.com/samber/lo/exp/simd | — | 1.25+ (amd64 only) |
Start with lo. Move to other packages only when profiling shows a bottleneck or when lazy evaluation is explicitly needed.
| Package | Use when | Trade-off |
| --- | --- | --- |
| lo | Default for all transforms | Allocates new collections (safe, predictable) |
| lop | CPU-bound work on large datasets (1000+ items) | Goroutine overhead; not for I/O or small slices |
| lom | Hot path confirmed by pprof -alloc_objects | Mutates input — caller must understand side effects |
| loi | Large datasets with chained transforms (Go 1.23+) | Lazy evaluation saves memory but adds iterator complexity |
| simd | Numeric bulk ops after benchmarking (experimental) | Unstable API, may break between versions |
Key rules:
lop is for CPU parallelism, not I/O concurrency — for I/O fan-out, use errgroup insteadlom breaks immutability — only use when allocation pressure is measured, never assumedloi eliminates intermediate allocations in chains like Map → Filter → Take by evaluating lazilygolang-samber-ro skill + samber/ro packageFor detailed package comparison and decision flowchart, see Package Guide.
// ✓ lo — declarative, type-safe
names := lo.Map(users, func(u User, _ int) string {
return u.Name
})
// ✗ Manual — boilerplate, error-prone
names := make([]string, 0, len(users))
for _, u := range users {
names = append(names, u.Name)
}
total := lo.Reduce(
lo.Filter(orders, func(o Order, _ int) bool {
return o.Status == "paid"
}),
func(sum float64, o Order, _ int) float64 {
return sum + o.Amount
},
0,
)
byStatus := lo.GroupBy(tasks, func(t Task, _ int) string {
return t.Status
})
// map[string][]Task{"open": [...], "closed": [...]}
results, err := lo.MapErr(urls, func(url string, _ int) (Response, error) {
return http.Get(url)
})
| Mistake | Why it fails | Fix |
| --- | --- | --- |
| Using lo.Contains when slices.Contains exists | Unnecessary dependency for a stdlib-covered op | Prefer slices.Contains/slices.Sort since Go 1.21+ and slices.Collect(maps.Keys(m)) since Go 1.23+ when a key slice is needed |
| Using lop.Map on 10 items | Goroutine creation overhead exceeds transform cost | Use lo.Map — lop benefits start at ~1000+ items for CPU-bound work |
| Assuming lo.Filter modifies the input | lo is immutable by default — it returns a new slice | Use lom.Filter if you explicitly need in-place mutation |
| Using lo.Must in production code paths | Must panics on error — fine in tests and init, dangerous in request handlers | Use the non-Must variant and handle the error |
| Chaining many eager transforms on large data | Each step allocates an intermediate slice | Use loi (lazy iterators) to avoid intermediate allocations |
slices.Contains and slices.Sort (Go 1.21+) carry no dependency; maps.Keys is Go 1.23+ and returns an iterator, so use slices.Collect(maps.Keys(m)) when you need a slice. Use lo for transforms the stdlib doesn't offer (Map, Filter, Reduce, GroupBy, Chunk, Flatten)lo.Filter → lo.Map → lo.GroupBy instead of writing nested loops. Each function is a building blocklo to lom/lop only after go tool pprof confirms allocation or CPU as the bottlenecklo.MapErr over lo.Map + manual error collection. Error variants stop early and propagate cleanlylo.Must only in tests and init — in production, handle errors explicitly| Function | What it does |
| --- | --- |
| lo.Map | Transform each element |
| lo.Filter / lo.Reject | Keep / remove elements matching predicate |
| lo.Reduce | Fold elements into a single value |
| lo.ForEach | Side-effect iteration |
| lo.GroupBy | Group elements by key |
| lo.Chunk | Split into fixed-size batches |
| lo.Flatten | Flatten nested slices one level |
| lo.Uniq / lo.UniqBy | Remove duplicates |
| lo.Find / lo.FindOrElse | First match or default |
| lo.Contains / lo.Every / lo.Some | Membership tests |
| lo.Keys / lo.Values | Extract map keys or values |
| lo.PickBy / lo.OmitBy | Filter map entries |
| lo.Zip2 / lo.Unzip2 | Pair/unpair two slices |
| lo.Range / lo.RangeFrom | Generate number sequences |
| lo.Ternary / lo.If | Inline conditionals |
| lo.ToPtr / lo.FromPtr | Pointer helpers |
| lo.Must / lo.Try | Panic-on-error / recover-as-bool |
| lo.Async / lo.Attempt | Async execution / retry with backoff |
| lo.Debounce / lo.Throttle | Rate limiting |
| lo.ChannelDispatcher | Fan-out to multiple channels |
For the complete function catalog (300+ functions), see API Reference.
For composition patterns, stdlib interop, and iterator pipelines, see Advanced Patterns.
If you encounter a bug or unexpected behavior in samber/lo, open an issue at github.com/samber/lo/issues.
golang-samber-ro skill for reactive/streaming pipelines over infinite event streams (samber/ro package)golang-samber-mo skill for monadic types (Option, Result, Either) that compose with lo transformsgolang-data-structures skill for choosing the right underlying data structuregolang-performance skill for profiling methodology before switching to lom/lopdata-ai
JS/TS 异步与并发——Promise、`async/await`、并发上限(`Promise.all`/`allSettled`/`p-limit`)、错误传播、取消(`AbortController`/`AbortSignal`)、超时、背压、`worker_threads`、事件循环模型。
development
Pinia stores, state management patterns, store setup, and reactivity with stores.
tools
JSX syntax in Vue (e.g., class vs className, JSX plugin config).
development
Golang skills orchestrator — always active on any Golang coding, review, debug, or setup task. Reads the task context and loads the most relevant skills from samber/cc-skills-golang, often multiple at once: writing a gRPC service loads golang-grpc + golang-testing + golang-error-handling; debugging a panic loads golang-troubleshooting + golang-safety; auditing security loads golang-security + golang-lint + golang-safety. Also: disambiguates competing clusters when two skills seem to overlap (performance vs benchmark vs troubleshooting, samber/lo vs mo vs ro, DI cluster, safety vs security), and configures CLAUDE.md or AGENTS.md to force-trigger skills in a project (/golang-how-to configure).