Skip to content

✨ feat(eval): support .[] iterator for arrays and dicts#1719

Merged
harehare merged 2 commits into
mainfrom
feat/array-dict-iterator-selector
May 11, 2026
Merged

✨ feat(eval): support .[] iterator for arrays and dicts#1719
harehare merged 2 commits into
mainfrom
feat/array-dict-iterator-selector

Conversation

@harehare
Copy link
Copy Markdown
Owner

  • 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
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 11, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks


Comparing feat/array-dict-iterator-selector (d938219) with main (5151f74)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (527244e) during the generation of this report, so 5151f74 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

- .[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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 or NONE if 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_args adds .[] 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 same Selector::List(None, None) + empty-args special-case in the RuntimeValue::Dict arm 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],

Comment thread crates/mq-lang/src/eval.rs
Comment thread crates/mq-lang/src/eval.rs
Comment thread crates/mq-lang/tests/integration_tests.rs
@harehare harehare merged commit bd2a753 into main May 11, 2026
14 checks passed
@harehare harehare deleted the feat/array-dict-iterator-selector branch May 11, 2026 13:49
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.

2 participants