Add a recursive object merge strategy and bind it to *

This commit adds a jv_object_merge_recursive function, that performs
recursive object merging, and binds it to multiply when applied to
two objects.

Added docs and tests.

Closes #320
This commit is contained in:
Filippo Valsorda committed 2014-03-08 03:56:05 +01:00
1 parent 219bb9ecb7
commit 2aa8a43c5b
5 files changed
+44 -1

No files matched your search

+10 -1
View File
@@ -479,7 +479,8 @@ sections:
- **Objects** are added by merging, that is, inserting all
the key-value pairs from both objects into a single
combined object. If both objects contain a value for the
same key, the object on the right of the `+` wins.
same key, the object on the right of the `+` wins. (For
recursive merge use the `*` operator.)
`null` can be added to any value, and returns the other
value unchanged.
@@ -527,6 +528,11 @@ sections:
Dividing a string by another splits the first using the second
as separators.
Multiplying two objects will merge them recursively: this works
like addition but if both objects contain a value for the
same key, and the values are objects, the two are merged with
the same strategy.
examples:
- program: '10 / . * 3'
input: 5
@@ -534,6 +540,9 @@ sections:
- program: '. / ", "'
input: '"a, b,c,d, e"'
output: ['["a","b,c,d","e"]']
- program: '{"k": {"a": 1, "b": 2}} * {"k": {"a": 0,"c": 3}}'
input: 'null'
output: ['{"k": {"a": 0, "b": 2, "c": 3}}']
- title: `length`
body: |