Please observe the result of these forEach, (1. and 2.):
1.
a!forEach( items: {1,2,3,4,5}, expression: if ( fv!item > 3, fv!item, {} )
)
results in
meanwhile
2.
a!forEach( items: {1,2,3,4,5}, expression: if ( fv!item > 3, fv!item, null )
Question: Why forEach 1. does not outcome five members in the list?, I expected this result
Discussion posts and replies are publicly visible
a!forEach() automatically flattens results.{} (Empty array) -> Gets flattened awaynull -> Get preserved
Shubham Aware said:a!forEach() automatically flattens results.
There's actually an important corner case that would make me hesitant to put it this simply - since it specifically *doesn't* (exactly) flatten results - that is, when the result is all empty sets, it will return an array of empty sets (where the average user might want to have just gotten back an empty array). When this is a possibility, it's necessary to wrap the a!forEach() call in a!flatten() which actually does flatten the result.