1

I tried to destructure a list in a lambda function, like this:

var matched = reduce(
    mapnew(lines, (_, x) => [strpart(x, 0, 1), strpart(x, 2, 1)]), 
    (acc, [a, b]) => acc && a == "a" && b == "b",
    1)

It seems [a, b] in the lambda arguments is not possible. Is there another way to name items of this list without resorting to indexing the array directly?

1 Answer 1

0

Move de-structuring out explicitly. (untested code)

var reducer = (acc, parts) => {
    [a, b] = parts
    return acc && a == "a" && b == "b"
    }
var matched = lines
    ->mapnew((_, x) => [strpart(x, 0, 1), strpart(x, 2, 1)])
    ->reduce( reducer, 1)
1
  • Thanks! fixed..
    – balki
    Commented Sep 22, 2023 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.