Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass a reference to a function as a function argument #651

Open
saig0 opened this issue May 30, 2023 · 0 comments
Open

Pass a reference to a function as a function argument #651

saig0 opened this issue May 30, 2023 · 0 comments

Comments

@saig0
Copy link
Member

saig0 commented May 30, 2023

Describe the bug
I want to sort a list of items using the sort() function. To improve the readability of the expression, I want to define the sorting function before, inside the same context.

{
  by_prio: function (x,y) x.prio < y.prio,
  sorted: sort(items, by_prio)
}

But it doesn't work and the sort() function returns null.

If I inline the sorting function then it works as expected.

{
  sorted: sort(items, function (x,y) x.prio < y.prio)
}

Note that this is a general issue that the function definition can not be accessed as a variable. But it can be invoked as a function.

{
  greeting: function (x) "Hello " + string(x),
  test: greeting("FEEL")
}
// works: "Hello FEEL"

{
  greeting: function (x) "Hello " + string(x),
  test: greeting instance of function
}
// failed to evaluate expression '{
//  greeting: function (x) "Hello " + string(x),
//  test: greeting instance of function
// }': no variable found for name 'greeting'

To Reproduce
Steps to reproduce the behavior:

  1. Evaluate the following expression:
{
  by_prio: function (x,y) x.prio < y.prio,
  sorted: sort(items, by_prio)
}

With the context:

{"items": [
  {"id": 1, "prio": 1},
  {"id": 2, "prio": 3},
  {"id": 3, "prio": 2}
]}
  1. Verify that the result is null

Expected behavior
I can pass a reference to a function definition as a function argument to the sort() function.

In general, I can access a reference to a function definition, for example, to check that the type of the reference is a function.

Environment

  • FEEL engine version: 1.16.0
  • Affects:
    • Camunda Automation Platform 7: [7.x]
    • Zeebe broker: [0.x]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant