Repository navigation
$each / $merge iterate arrays like JS for..in - #131
Merged
Merged
Conversation
sergeevik
reviewed
Nov 4, 2026
sergeevik
reviewed
Nov 4, 2026
| // Java: JS "for (var key in obj)" also iterates arrays (keys are the indexes as strings). | ||
| // Can happen where the signature is not validated, e.g. $each(?, ...) | ||
| var list = (List)obj; | ||
| for (int i=0; i<list.size(); i++) { |
Contributor
There was a problem hiding this comment.
this is a one-time cast, unlike the code above.
Addresses review comments on #131. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
First of three PRs split out of #130 (partial function application, #95). This one has no dependencies and should be merged first.
What changed
Functions.each(Object obj, Object func)(wasMap obj): whenobjis aList, it goes through the elements and passes the index as a string key ("0","1", …), like JSfor (var key in obj). Maps work as before.Functions.merge: array entries are merged as{"0": …, "1": …}. Entries that are neither a list nor a map are skipped instead of throwing aClassCastException.Why
In jsonata-js,
for..inalso goes through arrays. Signature validation (<o-f?:a>,<a<o>:o>) normally keeps arrays out of these functions, but some calls skip the signature check, e.g. partial application in jsonata-js ([5,6] ~> $each(?, …), #79). Without this change, the upcoming partial-application PR would turn the current T0410 error into aClassCastException.Notes for reviewers
$each([5,6], …)directly is still rejected with T0410, and a test checks this.each's parameter type changed fromMaptoObject. This only matters to Java code that callsFunctions.eachdirectly.Testing
New
EachMergeTest(12 cases). The tests register custom functions without a signature ($eachRaw/$mergeRaw) so that arrays reacheach/merge. Full suite: 1748 tests, 0 failures.🤖 Generated with Claude Code