-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add Map helpers #409
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #409 +/- ##
==========================================
+ Coverage 41.88% 42.06% +0.17%
==========================================
Files 271 272 +1
Lines 16245 16295 +50
==========================================
+ Hits 6804 6854 +50
Misses 8835 8835
Partials 606 606 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, Bro. The functions are basically fine. Just use generic for them if they can.
support/object/object.go
Outdated
) | ||
|
||
// Add an element to a map using “dot” notation if it doesn't exist. | ||
func Add(obj *map[string]any, k string, v any) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: Use generic here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only support string as a key so there is no point of using generic.
Hi Bro, If this PR is ready for review, please add the |
As we discussed, I can't implement nested key feature for all cases. So I am not working on this feature anymore. |
Some of the methods are good, don't you want to merge them? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, the test cases are very good. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect
RelatedTo: goravel/goravel#82
📑 Description
This pull request introduces a set of map helper methods to enhance map manipulation in Go.
Supported Methods
Add
: Add an element to a map if it doesn't exist.Exists
: Check if the given key exists in the provided map.Forget
: Remove a given key or keys from the provided map.Get
: Retrieve an element from map.Has
: Check if the given key or keys exist in the provided map.HasAny
: Check if any of the given keys exist in the provided map.Only
: Return the items in the map with the specified keys.Pull
: Return a new map with the specified keys removed.Set
: Set an element to a map using “dot” notation.Where
: filters the items in a map using the given callback.✅ Checks