project/1, query/1 and unify/1 added to builtin.jq, with tests and documentation #1062
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.
make check
ran successfully.Summary:
Description:
unify/1 is defined so as to achieve the following basic principles, where
it is to be understood that x, y and z are valid JSON values:
Semantics of (x|unify(y))
Terminology:
If x and y are not both null but x|unify(y) is null, then the unification of x and y is said to fail.
If x and y are two scalars, then x|unify(y) is:
if x == y then x elif x == null then y elif y == null then x else null end;
if x and y are two objects, and if $keys is (x + y) | keys | unique,
then (x|unify(y)) is the sum of {($k): (x[$k] | unify(y[$k]) )} as $k ranges through $keys,
provided that none of these values reflects unification failure;
if x and y are two arrays of the same length,
and if z is the array formed from (x[i]|unify(y[i]))
and if z[i] is only null when x[i] and y[i] are both null,
then (x|unify(y)) is z;
otherwise x|unify(y) is null.
Notice that: