Skip to content

Partial application of callables and lambdas without declared arity (#83) - #133

Merged
aeberhart merged 2 commits into
mainfrom
83-partial-arity
Nov 5, 2026
Merged

aeberhart merged 2 commits into
mainfrom
83-partial-arity

Conversation

@aeberhart

Copy link
Copy Markdown
Contributor

Third of three PRs split out of #130. Builds on #131 and #132 (both merged). With this one, everything in #130 is covered and #130 can be closed.

Fixes #83

Why

#132 made native partial application work like jsonata-js, but it gets the arity of a JFunction only from its implementing Method or its signature. jsonata-js takes the parameters of a native function from func.toString(). Custom functions registered without a signature, and Fn* lambdas, had no arity, so $add(1, 2) ~> $add(?, 3) failed for them.

Arity of Java functions

JFunction.getNumberOfArgs() now uses, in order:

  1. the parameters of the implementing Method
  2. the declared arity of a JLambda (Fn0–Fn8 → 0–8), kept by the Jsonata.function(...) factories
  3. the number of parameters in the signature
  4. unknown (a plain JFunctionCallable or FnVarArgs without signature): the number of args supplied at the partial application, e.g. $add(?, 3) → 2. This is the only deviation from JS: extra args are not dropped and missing ones are not bound.

It also implements the JS typeof proc === 'function' branch in partialApply, so Fn* lambdas bound via Frame.bind(...) can be partially applied (before this they failed with T1008).

API note

JLambda was an empty marker interface. It now declares getJFunctionCallable() and a default getNumberOfArgs(). All Fn* types implement both, but a class implementing JLambda directly would need to add getJFunctionCallable().

Testing

🤖 Generated with Claude Code

aeberhart and others added 2 commits November 5, 2026 11:26
- JLambda (Fn0..Fn8) reports its number of declared parameters, which
  JFunctions created via Jsonata.function(...) keep
- arity unknown (callable / FnVarArgs without signature): use the number
  of args supplied at the partial application
- implement the JS "typeof proc === 'function'" branch: lambdas bound via
  Frame.bind can be partially applied

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
These need the arity of a JFunctionCallable without signature (#83).
Also update the PartialTest comments: the cases are no longer gaps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Test Results

1 844 tests  +5   1 842 ✅ +5   7s ⏱️ -1s
  126 suites ±0       2 💤 ±0 
  126 files   ±0       0 ❌ ±0 

Results for commit 46d2bcd. ± Comparison against base commit f1e24f6.

@aeberhart
aeberhart merged commit 8f7b6aa into main Nov 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant