feat: Add Any, All, ContainsAll, ContainsAny, Random, First, Last, and driver.Valuer#25
Merged
feat: Add Any, All, ContainsAll, ContainsAny, Random, First, Last, and driver.Valuer#25
Conversation
…d driver.Valuer Add predicate functions (Any/All), variadic membership checks (ContainsAll/ContainsAny), non-destructive Random element selection (O(1) for ordered sets, O(n) for unordered), First/Last accessors for OrderedSet, and driver.Valuer on all set types to complement the existing sql.Scanner support. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds several utility functions for set operations and implements database integration support across all set types. The changes enhance the API with predicate functions (Any/All), membership checks (ContainsAll/ContainsAny), random element selection, and ordered set accessors (First/Last). Additionally, all five set types now implement driver.Valuer to complement the existing sql.Scanner implementation.
Changes:
- Added predicate functions
AnyandAllwith short-circuit evaluation for testing set elements against conditions - Added
ContainsAllandContainsAnyvariadic functions for convenient membership checks - Added
Randomfunction for non-destructive random element selection (O(1) for ordered sets, O(n) for unordered) - Added
FirstandLastaccessor functions for OrderedSet types - Implemented
driver.Valuerinterface on all 5 set types for database/sql integration - Updated README with new SQL section and comprehensive documentation of new functions
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| set.go | Core implementation of Any, All, ContainsAll, ContainsAny, and Random functions |
| ordered_set.go | Implementation of First and Last accessor functions for ordered sets |
| map.go | Added driver.Valuer implementation for Map set type |
| sync.go | Added driver.Valuer implementation for SyncMap set type |
| locked.go | Added driver.Valuer implementation for Locked set type |
| ordered.go | Added driver.Valuer implementation for Ordered set type |
| locked_ordered.go | Added driver.Valuer implementation for LockedOrdered set type |
| set_test.go | Comprehensive state machine tests for all new functions across all set types |
| examples_test.go | Example tests demonstrating usage of all new functions |
| README.MD | Documentation updates with SQL section and new function descriptions |
| .gitignore | Added .claude/settings.local.json to ignore list |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Any/Allpredicate functions with short-circuit evaluationContainsAll/ContainsAnyvariadic convenience functions for membership checksRandomfor non-destructive random element selection (O(1) for ordered sets viaAt, O(n) for unordered)First/Lastaccessors forOrderedSetdriver.Valueron all 5 set types (Map,SyncMap,Locked,Ordered,LockedOrdered) to complement existingsql.ScannerTest plan
Any,All,ContainsAll,ContainsAny,Random, andValuer— tested across all 5 set types via rapid property-based testingTestFirst_Last_OrderedandTestFirst_Last_LockedOrderedtestsgo test -v -race ./...passesgo vet ./...cleanstaticcheck ./...clean🤖 Generated with Claude Code