Skip to content
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

Merged
merged 12 commits into from
Feb 12, 2024
Merged

feat: Add Map helpers #409

merged 12 commits into from
Feb 12, 2024

Conversation

kkumar-gcc
Copy link
Member

@kkumar-gcc kkumar-gcc commented Feb 4, 2024

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

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

Copy link

codecov bot commented Feb 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5361d86) 41.88% compared to head (a16dad2) 42.06%.

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.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@hwbrzzl hwbrzzl left a 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 Show resolved Hide resolved
)

// 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: Use generic here.

Copy link
Member Author

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.

support/object/object.go Outdated Show resolved Hide resolved
@kkumar-gcc kkumar-gcc changed the title feat: Add Object helpers feat: Add Map helpers Feb 5, 2024
@hwbrzzl
Copy link
Contributor

hwbrzzl commented Feb 8, 2024

Hi Bro, If this PR is ready for review, please add the Review Ready tag.

@kkumar-gcc
Copy link
Member Author

kkumar-gcc commented Feb 8, 2024

As we discussed, I can't implement nested key feature for all cases. So I am not working on this feature anymore.

@hwbrzzl
Copy link
Contributor

hwbrzzl commented Feb 8, 2024

Some of the methods are good, don't you want to merge them?

support/maps/maps.go Outdated Show resolved Hide resolved
support/maps/maps.go Outdated Show resolved Hide resolved
support/maps/maps.go Outdated Show resolved Hide resolved
support/maps/maps.go Outdated Show resolved Hide resolved
support/maps/maps.go Outdated Show resolved Hide resolved
support/maps/maps.go Outdated Show resolved Hide resolved
support/maps/maps.go Outdated Show resolved Hide resolved
Copy link
Contributor

@hwbrzzl hwbrzzl left a 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. 👍

support/maps/maps_test.go Outdated Show resolved Hide resolved
support/maps/maps_test.go Show resolved Hide resolved
support/maps/maps_test.go Outdated Show resolved Hide resolved
support/maps/maps_test.go Outdated Show resolved Hide resolved
support/maps/maps_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect

@kkumar-gcc kkumar-gcc merged commit 4c01303 into master Feb 12, 2024
10 checks passed
@kkumar-gcc kkumar-gcc deleted the kkumar-gcc/object branch February 12, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants