feat: add array set operations ($union, $intersection, $difference, $symmetricDifference) - #829
Open
imshawan wants to merge 1 commit into
Open
feat: add array set operations ($union, $intersection, $difference, $symmetricDifference)#829imshawan wants to merge 1 commit into
imshawan wants to merge 1 commit into
Conversation
…symmetricDifference) - Implemented array set logic using deep equality - Added function bindings to static frame - Added extensive test suites using standard primitive and sequence datasets - Documented new functions in array-functions.md Signed-off-by: Shawan Mandal <github@imshawan.dev>
Author
|
Hi @andrew-coleman , tagging you here in case this got lost in the notifications shuffle. Let me know if this looks good to go or if you'd like any revisions! |
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.
Hola! 👋
This PR adds four standard array set operations to JSONata:
$union,$intersection,$difference, and$symmetricDifference.Right now, if you want to compare or combine two separate arrays and filter out the duplicates, it requires writing some pretty complex custom expressions. These new functions make basic set math super easy right out of the box. They naturally use JSONata's existing deep-equality checks, so nested objects work exactly as expected.
What these operations do:
$union(array1, array2): Combines two arrays into a single array, removing all duplicates.$intersection(array1, array2): Returns only the items that exist in both arrays.$difference(array1, array2): Subtracts the second array from the first, returning items that exist only in the first array.$symmetricDifference(array1, array2): Returns items that exist in either array, but NOT in both.Crucially, all of these functions rely entirely on JSONata's existing internal deep-equality checks. This means they don't just work on flat arrays of strings or numbers—they seamlessly handle complex, nested objects (e.g.
[{"id": 1}, {"id": 2}]) identically to how$distinctcurrently operates.What's inside:
src/functions.js. To keep things consistent, they rely on the exact same internal deep-equality logic that$distinctalready uses.<a-a:a>signature injsonata.jsso they play perfectly with context injection and path sequences.test/test-suite/groups/. They test primitives, deep object equality, missing/undefined arguments, and sequence datasets (viadataset5).docs/array-functions.mdusing the existing formatting.Sanity Checks:
npm run check-coveragestill hits exactly 100% globally.npm run lintpasses without any errors.Let me know if there's anything you'd like me to tweak or if you have any questions!