Skip to main content
Known Participant
February 5, 2025
Question

Problem with list of lists

  • February 5, 2025
  • 8 replies
  • 0 views

input : {{1,3},{2,3},{4,5},{5,6}}

output : {3,6,20,30}

We have to get product of each item(i.e list) in the array.

Please help me out with this issue

8 replies

sarathkumr268295
February 5, 2025

a!localVariables(
  local!a: {
    a!map(input: { 1, 3 }),
    a!map(input: { 2, 3 }),
    a!map(input: { 4, 5 }),
    a!map(input: { 5, 6 })
  },
  local!output: a!forEach(
    local!a.input,
    reduce(fn!product, 1, fv!item, 1)
  ),
  local!output
)


your input will convert into one single array instead of being separated into 4 different array if you declare using curly brackets. You have to declare using map to maintain the structure

Known Participant
February 5, 2025

Is there any way to convert the list of list(i.e {{1,3},{2,3},{4,5},{5,6}})  to a

list of map (i.e

{

a!map(input: { 1, 3 }),
a!map(input: { 2, 3 }),
a!map(input: { 4, 5 }),
a!map(input: { 5, 6 })
},) 

mikes0011
Brainy
February 5, 2025

Appian does not handle list-of-lists well at all (and never has).  You can attempt to call a!forEach() over your list-of-lists, but there's no guarantee it won't just iterate over each item individaully.  It also largely depends on where you're getting your input data, which you haven't specified.

kalpeshg0081
February 6, 2025

Hi [mention:533bc7b80dc643f99e9a93ecb946b71e:e9ed411860ed4f2ba0265705b8793d05] ,

i tried solving the above problem with a foreach(). here is my code.

a!localVariables(
  local!input: { { 1, 3 }, { 2, 3 }, { 4, 5 }, { 5, 6 } },
  local!even: a!forEach(
    items: local!input,
    expression: if(mod(fv!index, 2) = 0, fv!item, {})
  ),
  local!odd: a!forEach(
    items: local!input,
    expression: if(mod(fv!index, 2) = 0, {}, fv!item)
  ),
  a!forEach(
    items: local!odd,
    expression: fv!item * (index(local!even, fv!index, 0))
  )
)

mikes0011
Brainy
February 6, 2025

Really, everything we need to know about how appian (fails to) handle list-of-lists can be seen with how it resolves the value stored in local!input:

mikes0011
Brainy
February 6, 2025

The only exception I've ever really seen to the above is how the result of merge() is treated - because for whatever reason, list-of-list data seems to be honored (to a certain extent) in this context (and perhaps this context alone).  It's very frustrating since merge() is pretty unintuitive to understand and to use for real-world cases.