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

add method to Atom that preserves the index of the passed list #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Chris4942
Copy link

Why?

My use case for fuzzy string matching requires knowing the index of the thing that was matched as that index is a value on an object in a list and I want to be able to go back into that list and grab the object.

Aside: To see exactly how I'm using this see this PR. The part that pertains to this is the closure referenced on the line that I'm linking to.

What?

I added match_list_with_index to both Atom and Pattern. My use case relies on Pattern, but it seemed like the interface for Atom and Pattern are similar and so I added it to both to maintain parity between the two.

Testing

I tested it locally in my project and it does what I'm expecting there. See this PR.

If you would like to see unit tests, I'm happy to write some.

Other considerations

I considered trying to encapsulate the common logic between match_list and match_list_with_index into a common function that takes closures as arguments; however, the function is so short that that did not seem worthwhile and would likely add unneeded complexity.

I considered adding the index to the end of the tuple in the already existing function; however, I don't want to change the return type as that could break projects using this package and I certainly shouldn't be introducing breaking changes as a new contributor.

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.

1 participant