Forum Discussion
Recursive LAMBDA implementation of Excel's REDUCE function.
If function by function - maybe. If Microsoft goes this way most probably new functions like SCAN.EXT will be introduced with usual deployment cycle from Beta to production.
Performance is the key here. So far only PeterBartholomew1 approach gives more or less acceptable results on large arrays. As for IFNA() my impression it reduces performance dramatically. MAP() even more.
I had in mind wrapping the result with IFNA(SCAN2(...),"") rather than inserting extra conditions into the recursive definition which would likely have a considerable impact to performance. Using the following recursive let implementation also gave the same results as the LBROWN7 second formula
=LAMBDA(initial_value, array, function,
LET(
ret, LAMBDA(fn, initial_value, array,
IF(
COLUMNS(array) = 1,
function(initial_value, array),
LET(
acc, fn(fn, initial_value, DROP(array, , -COLUMNS(array) / 2)),
HSTACK(
acc,
fn(fn, TAKE(acc, , -COLUMNS(initial_value)), TAKE(array, , -COLUMNS(array) / 2))
)
)
)
),
IFNA(ret(ret, initial_value, array), "")
)
)({1, 2}, {2, 3, 4}, LAMBDA(a, b, VSTACK(a, b)))
P.S. I found this useful for the python code: Anonymous recursion - Wikipedia
- SergeiBaklanOct 16, 2023MVP
Great, it practically doesn't affect performance compare to initial SCAN2.
Thank you for the link, make the bookmark to read more carefully.