Socket
Book a DemoInstallSign in
Socket

tangled.org/oppi.li/sets

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tangled.org/oppi.li/sets

Go Modules
Version
v0.0.0-20251210075238-d0656dd747b1
Version published
Created
Source

sets

set datastructure for go with generics and iterators. the api is supposed to mimic rust's std::collections::HashSet api.

import "tangled.org/oppi.li/sets"

s1 := sets.Collect(slices.Values([]int{1, 2, 3, 4}))
s2 := sets.Collect(slices.Values([]int{1, 2, 3, 4, 5, 6}))

union     := sets.Collect(s1.Union(s2))
intersect := sets.Collect(s1.Intersection(s2))
diff      := sets.Collect(s1.Difference(s2))
symdiff   := sets.Collect(s1.SymmetricDifference(s2))

s1.Len()          // 4
s1.Contains(1)    // true
s1.IsEmpty()      // false
s1.IsSubset(s2)   // true
s1.IsSuperset(s2) // false
s1.IsDisjoint(s2) // false

if exists := s1.Insert(1); exists {
    // already existed in set
}

if existed := s1.Remove(1); existed {
    // existed in set, now removed
}

testing

includes property-based tests using the wonderful testing/quick module!

go test -v

FAQs

Package last updated on 10 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts