Repository: rayokota/jsonata-python

Issue:
Expression returns different results with pipe, reduce, and append.
For expression, `$.[{ }] ~> $reduce($append)` with input: `[true,true]`, the `js` implementation returns `[{},{}]` and `jsonata-python` returns: `[{},[{}]]`

Will spend some time debugging this if I get some time in the next few days!

Discussion:

Solution patch:
diff --git a/src/jsonata/functions.py b/src/jsonata/functions.py
index 951e1a1..e392f12 100644
--- a/src/jsonata/functions.py
+++ b/src/jsonata/functions.py
@@ -2010,15 +2010,9 @@ def append(arg1: Optional[Any], arg2: Optional[Any]) -> Optional[Any]:
             arg1 = utils.Utils.create_sequence(arg1)
         if not (isinstance(arg2, list)):
             arg2 = utils.Utils.JList([arg2])
-        # else
-        #     // Arg2 was a list: add it as a list element (don't flatten)
-        #     ((List)arg1).add((List)arg2)
 
         arg1 = utils.Utils.JList(arg1)  # create a new copy!
-        if isinstance(arg2, utils.Utils.JList) and arg2.cons:
-            arg1.append(arg2)
-        else:
-            arg1.extend(arg2)
+        arg1.extend(arg2)
         return arg1
 
     @staticmethod


Test patch:
diff --git a/tests/array_test.py b/tests/array_test.py
new file mode 100644
index 0000000..d999c0a
--- /dev/null
+++ b/tests/array_test.py
@@ -0,0 +1,7 @@
+﻿import jsonata
+
+
+class TestArray:
+
+    def test_array(self):
+        assert jsonata.Jsonata("$.[{ }] ~> $reduce($append)").evaluate([True, True]) == [{}, {}]