golang-samber-lo
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.).
Install / Use
npx skills add samber/cc-skills-golang --skill golang-samber-loInstalls into whichever agent you are using.
SKILL.md
Installable skill definition
Quality Score
Category
Development & EngineeringSupported Platforms
Our assessment of golang-samber-lo
golang-samber-lo scores 93/100 on our quality scale, 635th of 4,653 Development & Engineering skills we index (top 14%).
Its SKILL.md is 9.5 KB long, well organised into 13 sections with 5 code examples: a thorough specification that gives an agent plenty to work with.
With 3,324 GitHub stars, it is one of the more widely adopted skills in the catalogue.
Maintenance, license and trust
- The repository was last updated 25 days ago, so golang-samber-lo is actively maintained.
- It is released under the MIT license, a permissive license that allows use, modification and commercial use with attribution.
- Its trust signals score 100/100, with no cautions. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
Safety scan
No issues foundOur scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands.
Automated pattern scan on 2026-10-02. It catches known dangerous patterns, not every risk — read a skill before letting an agent act on it.
golang-samber-lo compared with similar skills
All 4 of these similar skills score higher than golang-samber-lo; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| golang-samber-lo (this skill)by samber | 93 | 3.3k | 25d ago | SKILL.md |
| Agent-Reachby Panniantong | 100 | 87.6k | 16d ago | CLAUDE.md |
| ai-job-searchby MadsLorentzen | 100 | 44.7k | today | CLAUDE.md |
| claude-howtoby luongnv89 | 100 | 41.7k | 2d ago | CLAUDE.md |
| algorithmic-artby anthropics | 100 | 177.9k | 9d ago | SKILL.md |
Frequently asked questions
- How do I install golang-samber-lo?
- Run
npx skills add samber/cc-skills-golang --skill golang-samber-lo. The install tabs above show the steps for each supported agent. - Which AI agents does golang-samber-lo work with?
- It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
- Is golang-samber-lo safe to use?
- Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. It is MIT-licensed and scores 100/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is golang-samber-lo still maintained?
- The repository was last updated 25 days ago, so golang-samber-lo is actively maintained.
Skill content
View source on GitHubname: golang-samber-lo
description: "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 samber/cc-skills-golang@golang-samber-ro skill)."
user-invocable: true
license: MIT
compatibility: Designed for Claude Code, Codex or similar harness, and for projects using Golang.
metadata:
author: samber
version: "1.2.2"
openclaw:
emoji: "🧰"
homepage: https://github.com/samber/cc-skills-golang
requires:
bins:
- go
install: []
skill-library-version: "1.53.0"
allowed-tools: Read Edit Write Glob Grep Bash(go:) Bash(golangci-lint:) Bash(git:) mcp__context7__resolve-library-id mcp__context7__query-docs AskUserQuestion Bash(godig:) Bash(gopls:) LSP mcp__gopls__
paths:
- "**/*.go"
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.
samber/lo — Functional Utilities for Go
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 — refer to library documentation and code examples for more information:
- For Go package docs, symbols, versions, importers, and known vulnerabilities, → See
samber/cc-skills-golang@golang-pkg-go-devskill (godig), preferred over Context7 for Go package facts. - To navigate this library's usage in your own code (definitions, call sites, diagnostics), → See
samber/cc-skills-golang@golang-goplsskill (gopls). - Context7 remains a fallback for docs not indexed on pkg.go.dev.
Why samber/lo
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:
- Type-safe generics — no
interface{}casts, no reflection, compile-time checking, no interface boxing overhead - Immutable by default — returns new collections, safe for concurrent reads, easier to reason about
- Composable — functions take and return slices/maps, so they chain without wrapper types
- Zero dependencies — only Go stdlib, no transitive dependency risk
- Progressive complexity — start with
lo, upgrade tolop/lom/loionly when profiling demands it - Error variants — most functions have
Errsuffixes (MapErr,FilterErr,ReduceErr) that stop on first error
Installation
go 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) |
Choose the Right Package
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:
lopis for CPU parallelism, not I/O concurrency — for I/O fan-out, useerrgroupinsteadlombreaks immutability — only use when allocation pressure is measured, never assumedloieliminates intermediate allocations in chains likeMap → Filter → Takeby evaluating lazily- For reactive/streaming pipelines over infinite event streams, → see
samber/cc-skills-golang@golang-samber-roskill +samber/ropackage
For detailed package comparison and decision flowchart, see Package Guide.
Core Patterns
Transform a slice
// ✓ 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)
}
Filter + Reduce
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,
)
GroupBy
byStatus := lo.GroupBy(tasks, func(t Task, _ int) string {
return t.Status
})
// map[string][]Task{"open": [...], "closed": [...]}
Error variant — stop on first error
results, err := lo.MapErr(urls, func(url string, _ int) (Response, error) {
return http.Get(url)
})
Common Mistakes
| 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 |
Best Practices
- Prefer stdlib when available —
slices.Containsandslices.Sort(Go 1.21+) carry no dependency;maps.Keysis Go 1.23+ and returns an iterator, so useslices.Collect(maps.Keys(m))when you need a slice. Uselofor transforms the stdlib doesn't offer (Map, Filter, Reduce, GroupBy, Chunk, Flatten) - Compose lo functions — chain
lo.Filter→lo.Map→lo.GroupByinstead of writing nested loops. Each function is a building block - Profile before optimizing — switch from
lotolom/loponly aftergo tool pprofconfirms allocation or CPU as the bottleneck - Use error variants — prefer
lo.MapErroverlo.Map+ manual error collection. Error variants stop early and propagate cleanly - Use
lo.Mustonly in tests and init — in production, handle errors explicitly
Quick Reference
| 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.
Cross-References
- → See
samber/cc-skills-golang@golang-samber-roskill for reactive/streaming pipelines over infinite event streams (samber/ropackage) - → See
samber/cc-skills-golang@golang-samber-moskill for monadic types (Option, Result, Either) that compose with lo transforms - → See
samber/cc-skills-golang@golang-data-structuresskill for choosing the right underlying data structure - → See
samber/cc-skills-golang@golang-performanceskill for profiling methodology before switching tolom/lop
Related Skills
Agent-Reach
87.6kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
ai-job-search
44.7kThe job search that runs on your machine. AI job application framework built on Claude Code: evaluate postings, tailor CVs, write cover letters, prep interviews. Fork it and own it.
claude-howto
41.7kA visual, example-driven guide to Claude Code — from basic concepts to advanced agents, with copy-paste templates that bring immediate value.
algorithmic-art
177.9kCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems.
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
