Forum Discussion
LBROWN7
Oct 09, 2023Brass Contributor
Recursive LAMBDA implementation of Excel's REDUCE function.
Not a question -- just sharing some interesting code. Out of curiosity, I decided to develop an implementation of Excel's REDUCE function as a recursive Excel LAMDA function. I was truly amazed how...
LBROWN7
Oct 10, 2023Brass Contributor
Hi Sergei:
Thanks for the info -- I was totally unaware that there was a way to calculate recursion limits ( aside from empirical testing)
Also, took me a while to figure out what you meant by LAMDA/ME. Going forward I will definately use ME for the recursive function name in the parameter list ( very descriptive)
As to your last comment regarding the utility of LAMDA/ME versus using helper functions. At this point the primary utility of LAMBDA/ME technique in this context is educational,
Thanks for your post.
Thanks for the info -- I was totally unaware that there was a way to calculate recursion limits ( aside from empirical testing)
Also, took me a while to figure out what you meant by LAMDA/ME. Going forward I will definately use ME for the recursive function name in the parameter list ( very descriptive)
As to your last comment regarding the utility of LAMDA/ME versus using helper functions. At this point the primary utility of LAMBDA/ME technique in this context is educational,
Thanks for your post.
SergeiBaklan
Oct 12, 2023MVP
Sorry, LAMBDA/ME is just the slang used at the beginning of lambdas in Excel. That's close to what you suggested. If take the latest of suggested by lori_m functions and put it in the cell without given a name, that could be like
=LAMBDA(array,function,
LET(
byRow2, LAMBDA(ME,arr,func,
IF( ROWS(arr) = 1, func(arr),
VSTACK(
ME( ME, TAKE(arr, ROWS(arr) / 2), func ),
ME( ME, DROP(arr, ROWS(arr) / 2), func ) )
) ),
byRow2(byRow2, array, function) )
)(range, fn)
or if not to wrap with lambda which, IMHO, more logical for in-cell formula
=LET(
byRow2, LAMBDA(ME,arr,func,
IF( ROWS(arr) = 1,
func(arr),
VSTACK(
ME( ME, TAKE(arr, ROWS(arr) / 2), func ),
ME( ME, DROP(arr, ROWS(arr) / 2), func ) )
)
),
byRow2(byRow2, array, fn) )