Bases formula with nested map functions

I got a bases formula with a map function in a map function and I need the value from the upper map in the lower map function.

for example

noteList.map( 
    file(value1).map( 
        file(value2).properties.num 
        * file(value1).properties.num
    )
)

Is there a way to do this, can you declare variables?

AFAIK, you cannot declare variables in bases formulas. However, you can always just write the function again inside your formula instead of assigning it to a variable. It looks a bit messy, but it works.

From your code, I’m not completely sure what you want to achieve, because you are not referencing the value of the first .map() in your second .map().
In general, functions cannot be recursive. So if the first .map() relies on the second .map(), which in turn requires the value of the first .map(), this can never work.

You can simulate variables by using another formula. Give formula a the value or formula you want to reuse. In other formulas, you can then type formula.a to reference it.

However, what are value1 and value2? If both of them are values conveyed by noteList, then no variable declaration is necessary.

Or if it’s a situation where you need to manipulate value1 (really just value) to get value2, then what you showed is essentially:

noteList.map(
  file(value.map("however you get to value2 from value1")).properties.num
  * file(value).properties.num
)
noteList.map1( 
    file(value1).properties.noteList.map2( 
        file(value2).properties.num 
        * file(value1).properties.num
    )
)

The values are the corresponding value of the map function, the problem is that value1 provides a file with another list of notes, to each of one (accessed by the map2 via value2) I want to multiply another property from value1

Understood now.

I’m not thinking clearly at the moment so apologies for the half effort here, but does it help to consider passing yourself all of the values in lists of lists? In the vein of:

noteList.map(
  [
    file(value).properties.num,
    file(value).properties.noteList.map(file(value).properties.num)
  ]
)

which would give you, essentially:

[1, [11, 12, 13] ],
[2, [21, 22, 23] ],
[3, [31, 32, 33] ]

… to work with.

The part I’m bailing on for the moment is mapping or reducing the products for:

1 x 11
1 x 12
1 x 13

2 x 21
2 x 22
etc.

Or does that leave you in the same pickle you began in?

Sorry for the late response, but I think I solved it with join()

noteList.map(

  (file(link(value)).properties.otherNotesList
  .map(

    file(link(value)).properties.num

   ).join(

    ", "
    + file(link(value)).properties.numList
    + "::"

  )
  + ", " 
  + file(link(value)).properties.numList
  )
  .split("::")
  .map(
    number(value.split(",")[0])
    * number(value.split(",")[index + 1])
  )
  .reduce(value + acc, 0)

)
Note1
  otherNotesList:
    - Note1.1
    - Note1.2
  numList: [6, 3]

Note1.1
  num: 5

Now the problem is that when I try to reduce the resulting list no result shows up

Way to make progress. Will try to look at it later. This is just a quick comment about a redundancy that jumps out:

You can replace each file(link(value)) with file(value).

Never mind it works now.
I also found a workaround with a second formula:

formula1:
noteList.map(

  file(link(value)).properties.otherNotesList
  .map(

    file(link(value)).properties.num

  )
).flat()
noteList.map(

  file(link(value)).properties.numList

).flat()
.map(value * formula1[index])
.reduce(acc + value, 0)

Nonetheless it would be nice to have a simpler approach.