-
Notifications
You must be signed in to change notification settings - Fork 125
Description
Hi there,
I’m experimenting with JSLT and ran into something I don’t fully understand. I’m trying to assign the result of a function to a variable using let, and then use that variable inside a nested for expression.
Here’s a simplified version of my code ( to test on demo playground ) :
def extract_and_add_text(values)
[
for(flatten([$values]))
let current_value = hello(.)
[for([$current_value])
( .)]
]
def hello(text)
"Hello " + $text + "!"
{
"url_update" : extract_and_add_text(.url),
* : .
}
In this case, i have a syntax exception: it seems like i can't use the for loop. But if I assign the value directly without passing from a function, the nested for works fine. Like this:
def extract_and_add_text(values)
[
for(flatten([$values]))
let current_value = (.)
[for([$current_value])
( .)]
]
def hello(text)
"Hello " + $text + "!"
{
"url_update" : extract_and_add_text(.url),
* : .
}
I have found different workarounds to this """""problem""""", but i would just like to understand why we arent allowed to use a function to for assignation before inner for-loop.
Just for information, one possible workaround is to use the function inside the inner loop, for example:
def extract_and_add_text(values)
[
for(flatten([$values]))
let current_value = (.)
[for([$current_value])
hello( .)]
]
def hello(text)
"Hello " + $text + "!"
{
"url_update" : extract_and_add_text(.url),
* : .
}