add method to Atom that preserves the index of the passed list #45
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.
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.
What?
I added
match_list_with_index
to bothAtom
andPattern
. My use case relies onPattern
, but it seemed like the interface forAtom
andPattern
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
andmatch_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.