"enumerate" equivalent: give the full path with the result
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.2k
- Forks
- 86
- PR merge metrics
- No merged PRs in 30d
Description
Python has the extremely-handy `enumerate` function, allowing you to iterate through a list and get the index of the current element. What's the team's view on adding similar functinality to Glom? Could be very useful for data exploration/validation (c.f. #7), so that you can find your way back to where a value came from.
Don't have a good idea of the best interface for this, but something like:
```
target = {
"foo": [
{"a": 1, "b": 2},
{"a": 3, "b": 4}
]
}
spec = ("foo", ["b"])
result = glom(target, spec, trace=True)
# [("foo.0.b", 2), ("foo.1.b", 4)]
```
So if I was `using` this to power a validator ensuring that, say, no "b" was greater than 3, it could do:
```
for path, value in result:
if value > 3:
print(f"Warning: {path} greater than 3!")
```
It seems like the information needed to power this is all there already, based on the output of a recursive `Inspect`. Is there already some easy way of achieving this that I'm missing?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the recursive `Inspect` behavior and the existing `glom(target, spec, trace=True)` entry point, which the issue identifies as related machinery. Done means an agreed interface for returning each result with its full path, suitable for locating values during validation or data exploration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100