✨ feat(eval): support .[] iterator for arrays and dicts#1719
Merged
Conversation
Owner
harehare
commented
May 11, 2026
- Arrays: .[] returns all elements as an array (identity passthrough)
- Dicts: .[] returns all values as an array
- Handles both args and no-args eval paths
- Arrays: .[] returns all elements as an array (identity passthrough) - Dicts: .[] returns all values as an array - Handles both args and no-args eval paths
- .[N] on RuntimeValue::Array now returns the element at index N - Out-of-bounds access returns none - Applied to both eval_selector_expr and eval_selector_expr_with_args
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends mq-lang’s evaluator to treat the selector syntax .[] as an iterator over runtime arrays and dicts (arrays passthrough; dicts yield values), and adds integration tests to validate the new behavior.
Changes:
- Add array indexing support for
.[n]in selector evaluation (return element orNONEif out-of-bounds). - Implement
.[]on arrays as an identity/passthrough and.[]on dicts as “values as array” (no-args path). - Add integration tests covering
.[]for arrays/dicts and.[n]indexing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/mq-lang/src/eval.rs | Adds selector handling for .[n] indexing and .[] iteration semantics in the evaluator. |
| crates/mq-lang/tests/integration_tests.rs | Adds integration cases verifying .[] and .[n] behavior for arrays and dicts. |
Comments suppressed due to low confidence (1)
crates/mq-lang/src/eval.rs:816
eval_selector_expr_with_argsadds.[]identity behavior for arrays (when args are empty), but the Dict branch doesn’t mirror this. As a result,{"a": 1} | .[]()(SelectorCall with empty args) will produce a dict of NONEs instead of returning the dict values as an array, and behavior differs between.[]and.[]()/ args vs no-args paths. Consider adding the sameSelector::List(None, None)+ empty-args special-case in theRuntimeValue::Dictarm here.
}
}
_ if matches!(selector, Selector::List(None, None)) && args.is_empty() => {
vec![value.clone()]
}
RuntimeValue::Dict(_) => {
vec![Self::eval_selector_expr_with_args(value, selector, args)]
}
_ => vec![RuntimeValue::NONE],
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.