Forum Discussion
THUNKS
Do you mean that if Lambda function is included in the array then one of the parameter that is either the row or the column argument of the INDEX function must be 1 to produce the output without throwing any error?
Is this the double Lambda setup is called as thunk or is it the double Lambda's wrapped inside BYROW function is called as thunk? Can you explain more about this thunk concept as without understanding of which it's difficult to understand the answers of the questions and to get the hang of the formula.
How is that the formula INDEX(sumsArray, 4, 1) returns a Lambda function and not an array of values consequently requiring a null parameter string? I see that sumsArray = Double Lambda's wrapped inside BYROW function and BYROW function fulfills the parameter passing requirement of Lambda function by feeding 'data' as parameter to the double Lambda's.
I regard a Thunk as a special case of a named Lambda function that requires no parameters but returns a predefined array when called with an empty parameter string. A single Thunk can be created by including the array as the final (and only) parameter to LAMBDA. It is also possible to pass the array as a parameter by using a further LAMBDA.
Thunkλ
= LAMBDA(x, LAMBDA(x))
This may not look useful but it does allow and array of Thunks to be built using a Lambda helper function such as BYROW.
Why might one use an array of Thunks? An example might be to create an array of range references, something that Excel will not allow. Instead, one may use an array of Thunks, anyone of which may be expanded to return a range reference. For example
tablesϑ
= VSTACK(
Thunkλ(Table1),
Thunkλ(Table2),
Thunkλ(Table3)
)
represents an array of 3 elements each of which is a thunk. Where things get interesting, is that the array can be used as an argument in a normal Excel function such as XLOOKUP. Thus
= LET(
selectedTblϑ, XLOOKUP(selectYr, years, tablesϑ),
selectedTblϑ()
)
The first line of code returns a single thunk and the second expands it to return a range reference to the data within a table which may be on any sheet of the workbook.
Alternatively
= REDUCE(headers, tablesϑ,
LAMBDA(acc,tblϑ, VSTACK(acc, tblϑ()))
)
will stack the contents of all three tables vertically as a single dynamic array.
I don't know whether this helps, but it may give a flavour of what is possible!