Uniq
Overview
Uniq returns unique elements in first-seen order (lodash uniq).
If you are coming from Node.js, the closest pattern is _.uniq(arr).
Signature
go
func Uniq[T comparable](in []T) []TCompare: Node.js · Standard Go · gox
js
const unique = _.uniq(items);go
seen := make(map[T]struct{})
var unique []T
for _, v := range items { /* dedupe */ }go
import "github.com/sahilkhaire/gox/slice"
unique := slice.Uniq(items)Example
go
import "github.com/sahilkhaire/gox/slice"
unique := slice.Uniq(items)Tips
Chain Filter, Map, and Reduce for lodash-style pipelines. Results are new slices — inputs are never mutated.
Standard library alternative
Use the standard library directly:
go
seen := make(map[T]struct{})
var unique []T
for _, v := range items { /* dedupe */ }