🔥bytedance/gg is a basic library of generics for Go language developed by ByteDance. It is based on the Go 1.18+ generic features and provides efficient, type-safe and rich generic data structures and tool functions.
❓Why this name?
Take the first letter of Go Generics, short and simple.
❓Why choose gg?
Stable and reliable: It is a necessary tool library for ByteDance R&D team, and it has 1w+ repository references inside.
Easy to use: With the design principle of simplicity and self-consistent, subcontracted according to functions, modular, semantic intuitive and unified, and low learning cost.
High Performance: Provides high-performance concurrent data structures, with performance 10+ times faster than standard library.
No three-party dependencies: Generic libraries will not introduce any three-party dependencies.
Version control: Follow the SemVer, guaranteeing backward compatibility.
add := Partial2(gvalue.Add[int]) // convert the Add function into a partial function
add1 := add.Partial(1) // Bind (i.e., "freeze") the first argument to 1
add1(0) // 0 + 1 = 1
// 1
add1(1) // Reuse the partially applied function: 1 + 1 = 2
// 2
add1n2 := add1.PartialR(2) // Bind the remaining (rightmost) argument to 2; all arguments are now fixed
add1n2() // 1 + 2 = 3
gg: Go Generics
English | 简体中文
🔥
bytedance/ggis a basic library of generics for Go language developed by ByteDance. It is based on the Go 1.18+ generic features and provides efficient, type-safe and rich generic data structures and tool functions.❓Why this name?
Take the first letter of Go Generics, short and simple.
❓Why choose gg?
🚀 Install
🔎 Table of contents
(T, bool)(T, error)T*T[]Tmap[K]Vfuncsyncmap[T]struct{}sync.Mapbelow Go 1.24sync.Mapbelow Go 1.24✨ Generic Functional Programming
goption
Option type, simplifying the processing of
(T, bool)Usage:
Example:
gresult
Result type, simplifying the processing of
(T, error)Usage:
Example:
✨ Generic Data Processing
gcond:
Conditional operation
Usage:
Example:
gvalue
Processing value
TUsage:
Example1:Zero Value
Example2:Math Operation
Example3:Comparison
Example4:Type Assertion
gptr
Processing pointer
*TUsage:
Example:
gslice
Processing slice
[]TUsage:
Example1:High-order Function
Example2:CURD Operation
Example3:Partion Operation
Example4:Math Operation
Example5:Convert to map
Example6:Set Operation
Example7:Re-order Operation
gmap
Processing map
map[K]VUsage:
Example1:Keys / Values Getter
Example2:High-order Function
Example3:CURD Operation
Example4:Partion Operation
Example5:Math Operation
Example6:Set Operation
gfunc
Processing function
funcUsage:
Example1:Partial Application
gconv
Data type conversion
Usage:
Example:
gson
Processing JSON
Usage:
Example:
✨ Generic Standard Wrapper
gsync
Wrap
syncUsage:
Example1:
gsync.Mapwrapssync.MapExample2:
gsync.Poolwrapssync.PoolExample3:
gsync.OnceXXXwrapssync.Once✨ Generic Data Structures
tuple
Implementation of tuple provides definition of generic n-ary tuples
Usage
Example:
set
Implementation of set based on
map[T]struct{}Usage
Example:
list
Implementation of doubly linked list
Usage
Example:
skipset
High-performance, scalable, concurrent-safe set based on skip-list, up to 15x faster than the built-in
sync.Mapbelow Go 1.24⚠️ NOTICE: Go 1.24 or later, please consider using the std
sync.Map, which has better performance compared toskipsetin about 90% of use cases.Usage
Example:
skipmap
High-performance, scalable, concurrent-safe map based on skip-list, up to 10x faster than the built-in
sync.Mapbelow Go 1.24⚠️ Go 1.24 or later, please consider using the std
sync.Map, which has better performance compared toskipmapin about 90% of use cases.Usage
Example:
License
ggis licensed under the Apache-2.0 license. See LICENSE for details.2025 © Bytedance