ConfigsJul 18, 2026·3 min read

Lancet — Comprehensive Utility Function Library for Go

A reusable Go utility library providing 600+ functions covering strings, slices, maps, concurrency, cryptography, file I/O, networking, and more, all using Go generics.

Agent ready

Ready-to-run agent install

This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
Lancet Overview
Direct install command
npx -y tokrepo@latest install 0916b73c-8243-11f1-9bc6-00163e2b0d79 --target codex

Run after dry-run confirms the install plan.

Introduction

Lancet is a Go utility library inspired by JavaScript's Lodash and Java's Apache Commons. It provides a broad collection of helper functions organized into packages, covering common operations that Go developers would otherwise write repeatedly. It leverages Go generics for type-safe collection operations.

What Lancet Does

  • Provides 600+ utility functions across 30+ packages for common Go tasks
  • Covers string manipulation, slice/map operations, math, file I/O, and HTTP helpers
  • Uses Go generics for type-safe collection functions like Filter, Map, Reduce, and GroupBy
  • Includes concurrency utilities, retry logic, and rate limiting helpers
  • Offers cryptography wrappers, random generation, and validation functions

Architecture Overview

Lancet is organized as a collection of focused packages within a single module. Each package (strutil, slice, maputil, fileutil, netutil, cryptoutil, etc.) is independent and can be imported individually. Functions are designed as pure, stateless utilities with no global state. Generics-based packages require Go 1.18+. The library has zero external dependencies — every function is implemented in pure Go.

Self-Hosting & Configuration

  • Install with go get github.com/duke-git/lancet/v2 — requires Go 1.18+
  • Import only the packages you need: lancet/v2/slice, lancet/v2/strutil, etc.
  • No configuration required — all functions are stateless utilities
  • Each package can be used independently without pulling in the entire library
  • Full documentation available at pkg.go.dev with examples for every function

Key Features

  • Zero dependencies — pure Go implementation with no external packages
  • Generics support — type-safe collection operations without interface{} casting
  • Comprehensive coverage — strings, slices, maps, math, datetime, file, net, crypto, system
  • Well-tested — each function includes unit tests and benchmark tests
  • Consistent API design — predictable naming and parameter conventions across packages

Comparison with Similar Tools

  • Lodash (JS) — Lancet serves the same role for Go that Lodash serves for JavaScript
  • samber/lo — another Go generics utility library; Lancet covers more domains beyond collections
  • thoas/go-funk — pre-generics utility library using reflection; Lancet uses generics for type safety
  • standard library — Go stdlib covers basics; Lancet fills gaps like CamelCase, Chunk, and Retry

FAQ

Q: Does Lancet require Go generics? A: The v2 branch requires Go 1.18+. A v1 branch exists for older Go versions but without generics-based functions.

Q: Will importing Lancet bloat my binary? A: No, Go only compiles the packages and functions you actually import and call.

Q: How stable is the API? A: Lancet follows semantic versioning. The v2 API is considered stable with backward-compatible additions.

Q: Can I contribute new utility functions? A: Yes, the project accepts contributions. New functions should include documentation, tests, and benchmarks.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets