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

feature: add index to gstruct element func #419

Merged
merged 1 commit into from Mar 3, 2021

Conversation

zach-source
Copy link
Contributor

This is a feature I've been missing and worked around with a custom counter struct. The use case is I have a small slice and just want to be able to reference the objects by index. I either sort the list or use matchers that don't care about order. I was able to add a way to make the index available while keeping backwards compatibility.

Changes

Add interface Identify - allow us to create interface funcs on top of existing code for backwards compatibility and flexibility.

Add new function IdentifierWithIndex. This identifier accepts an index along with element so you can use it in your string return value.

Add two new functions MatchElementsWithIndex, MatchAllElementsWithIndex. Essentially the same function as the original but swaps in the new IdenitiferWithIndex function so you can use the index.

Helper function IndexIdentify to provide an already created func for easy index use.

Final words

Happy to make any changes necessary. Just thought it would be helpful. Thanks!

@onsi
Copy link
Owner

onsi commented Feb 25, 2021

This looks good to me and makes sense. Do you mind adding some documentation on the gh-pages branch to this section as a separate PR?

THanks!

@zach-source
Copy link
Contributor Author

@onsi Awesome, don't mind at all.

zach-source added a commit to zach-source/gomega that referenced this pull request Feb 25, 2021
Added documentation to support the onsi#419 PR.
@zach-source
Copy link
Contributor Author

#421 opened for documentation.

@blgm
Copy link
Collaborator

blgm commented Mar 3, 2021

@onsi I see that you merged the documentation PR #421, did you mean to merge this implementation PR too, or was there something outstanding?

@onsi onsi merged commit 334e00d into onsi:master Mar 3, 2021
@onsi
Copy link
Owner

onsi commented Mar 3, 2021

lol omg - thanks for the ping @blgm !!

@zach-source
Copy link
Contributor Author

@onsi @blgm was also thinking the same thing but I just assumed you were waiting for a reason. Thanks for merging my contribution!

This was referenced Mar 8, 2021
@zach-source zach-source deleted the feature/element-index branch December 1, 2022 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants