Skip to content

Commit fa0a5fd

Browse files
committed
fix: restore support for JFunction and add test case
1 parent 13cc9c7 commit fa0a5fd

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/jsonata/functions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ def get_function_arity(func: Any) -> int:
15751575

15761576
return len(signature(func.function).parameters)
15771577
else:
1578-
raise RuntimeError(f"unexpected function '{type(func)}'")
1578+
return len(func.arguments)
15791579

15801580
#
15811581
# Helper function to build the arguments to be supplied to the function arg of the

tests/custom_function_test.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ def test_ternary(self):
2323
expression.register_lambda("abc", lambda x, y, z: str(x) + str(y) + str(z))
2424
assert expression.evaluate({"a": "a", "b": "b", "c": "c"}) == "abc"
2525

26-
def test_map(self):
26+
def test_map_with_lambda(self):
2727
expression = jsonata.Jsonata("$map([1, 2, 3], $square)")
2828
expression.register_lambda("square", lambda x: x * x)
2929
assert expression.evaluate(None) == [1, 4, 9]
30+
31+
def test_map_with_function(self):
32+
expression = jsonata.Jsonata("$map([1, 2, 3], function($v) { $v * $v })")
33+
assert expression.evaluate(None) == [1, 4, 9]

0 commit comments

Comments
 (0)