golang-samber-lo

samber/cc-skills-golang · updated Apr 8, 2026

MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.

$npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-lo
0 commentsdiscussion
summary

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.

skill.md

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. Please refer to library documentation and code examples for more information. Context7 can help as a discoverability platform.

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 to lop/lom/loi only when profiling demands it
  • Error variants — most functions have Err suffixes (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:

  • lop is for CPU parallelism, not I/O concurrency — for I/O fan-out, use errgroup instead
  • lom breaks immutability — only use when allocation pressure is measured, never assumed
  • loi eliminates intermediate allocations in chains like Map → Filter → Take by evaluating lazily
  • For reactive/streaming pipelines over infinite event streams, → see samber/cc-skills-golang@golang-samber-ro skill + samber/ro package

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, maps.Keys since Go 1.21+
Using lop.Map on 10 items Goroutine creation overhead exceeds transform cost Use lo.Maplop 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

  1. Prefer stdlib when availableslices.Contains, slices.Sort, maps.Keys carry no dependency. Use lo for transforms the stdlib doesn't offer (Map, Filter, Reduce, GroupBy, Chunk, Flatten)
  2. Compose lo functions — chain lo.Filterlo.Maplo.GroupBy instead of writing nested loops. Each function is a building block
  3. Profile before optimizing — switch from lo to lom/lop only after go tool pprof confirms allocation or CPU as the bottleneck
  4. Use error variants — prefer lo.MapErr over lo.Map + manual error collection. Error variants stop early and propagate cleanly
  5. Use lo.Must only 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-ro skill for reactive/streaming pipelines over infinite event streams (samber/ro package)
  • → See samber/cc-skills-golang@golang-samber-mo skill for monadic types (Option, Result, Either) that compose with lo transforms
  • → See samber/cc-skills-golang@golang-data-structures skill for choosing the right underlying data structure
  • → See samber/cc-skills-golang@golang-performance skill for profiling methodology before switching to lom/lop
how to use golang-samber-lo

How to use golang-samber-lo on Cursor

AI-first code editor with Composer

1

Prerequisites

Before installing skills in Cursor, ensure your development environment meets these requirements:

  • Cursor installed and configured on your development machine
  • Node.js version 16.0+ with npm package manager (verify with node --version)
  • Active project directory or workspace where you want to add golang-samber-lo
2

Execute installation command

Execute the skills CLI command in your project's root directory to begin installation:

$npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-lo

The skills CLI fetches golang-samber-lo from GitHub repository samber/cc-skills-golang and configures it for Cursor.

3

Select Cursor when prompted

The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:

◆ Which agents do you want to install to?
│ ── Universal (.agents/skills) ── always included ────
│ • Amp
│ • Antigravity
│ • Cline
│ • Codex
│ ●Cursor(selected)
│ • Cursor
│ • Windsurf
4

Verify installation

Confirm successful installation by checking the skill directory location:

.cursor/skills/golang-samber-lo

Reload or restart Cursor to activate golang-samber-lo. Access the skill through slash commands (e.g., /golang-samber-lo) or your agent's skill management interface.

Security & Verification Notice

We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.

Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.

List & Monetize Your Skill

Submit your Claude Code skill and start earning

GET_STARTED →

Use Cases

Task Automation & Efficiency

Automate repetitive workflows and reduce manual effort

Example

Generate reports, summarize documents, draft communications

Save 3-5 hours per week on routine tasks

Knowledge Enhancement

Learn new skills, understand complex topics, get expert guidance

Example

Explain concepts, provide examples, suggest learning resources

Accelerate learning and skill development by 2x

Quality Improvement

Enhance output quality through reviews, suggestions, and refinements

Example

Review drafts, suggest improvements, catch errors

Improve work quality by 30-40% with less effort

Implementation Guide

Prerequisites

  • Claude Desktop or compatible AI client with skill support
  • Clear understanding of task or problem to solve
  • Willingness to iterate and refine outputs

Time Estimate

15-45 minutes depending on use case complexity

Installation Steps

  1. 1.Install skill using provided installation command
  2. 2.Test with simple use case relevant to your work
  3. 3.Evaluate output quality and relevance
  4. 4.Iterate on prompts to improve results
  5. 5.Integrate into regular workflow if valuable

Common Pitfalls

  • Expecting perfect results without iteration
  • Not providing enough context in prompts
  • Using skill for tasks outside its intended scope
  • Accepting outputs without review and validation

Best Practices

✓ Do

  • +Start with clear, specific prompts
  • +Provide relevant context and constraints
  • +Review and refine all outputs before using
  • +Iterate to improve output quality
  • +Document successful prompt patterns

✗ Don't

  • Don't use without understanding skill limitations
  • Don't skip validation of outputs
  • Don't share sensitive information in prompts
  • Don't expect skill to replace human judgment

💡 Pro Tips

  • Be specific about desired format and style
  • Ask for multiple options to choose from
  • Request explanations to understand reasoning
  • Combine AI efficiency with human expertise

When to Use This

✓ Use When

Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.

✗ Avoid When

Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.

Learning Path

  1. 1Familiarize yourself with skill capabilities and limitations
  2. 2Start with low-risk, non-critical tasks
  3. 3Progress to more complex and valuable use cases
  4. 4Build expertise through regular use and experimentation

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.454 reviews
  • Olivia Torres· Dec 24, 2024

    Keeps context tight: golang-samber-lo is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • William Jackson· Dec 20, 2024

    golang-samber-lo has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Naina Gupta· Dec 12, 2024

    Registry listing for golang-samber-lo matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Kwame Shah· Dec 8, 2024

    Solid pick for teams standardizing on skills: golang-samber-lo is focused, and the summary matches what you get after install.

  • Chaitanya Patil· Dec 4, 2024

    golang-samber-lo fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Piyush G· Nov 23, 2024

    golang-samber-lo is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Noor Li· Nov 15, 2024

    We added golang-samber-lo from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Meera Brown· Nov 3, 2024

    Useful defaults in golang-samber-lo — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Meera Shah· Oct 22, 2024

    I recommend golang-samber-lo for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Shikha Mishra· Oct 14, 2024

    Keeps context tight: golang-samber-lo is the kind of skill you can hand to a new teammate without a long onboarding doc.

showing 1-10 of 54

1 / 6