Forum Discussion
What do you think of thunks?
It appears one can't edit the original post so I am replying to myself in order to update the workbook.
The key difference is that, although I have demonstrated the results of 9 distinct, but related, formulas, there are only two formula cells.
By bringing the calculation together within a single module, it became obvious that there was a lot of repetition, involving evaluating thunks and applying a in-built function to the result, functions that could be tidied up by writing a further Lambda function
CALCλ
= LAMBDA(values, n,
LET(
// Call ROLLINGRANGEλ to extract a rolling range of n cells from the range 'values'
arrayϑ, ROLLINGRANGEλ(values, n),
// Expand the thunks to give a 2D range for demonstrtion purposes
array, TRANSPOSE(EVALTHUNKARRλ(TOROW(arrayϑ))),
// demonstrate that the thunk array arrayϑ contains ranges and not simply arrays
isref?, MAPϑ(arrayϑ, ISREF),
// demonstrate that the ranges are of differing dimensions
rows, MAPϑ(arrayϑ, ROWS),
// calculate the average value over each range to give a rolling average
avrg, MAPϑ(arrayϑ, AVERAGE),
// calculate the maximum value over each range to give a rolling maximum
rmax, MAPϑ(arrayϑ, MAX),
// compare each value to its rolling maximum
isMax?, values = rmax,
// Stack reults for presentation
HSTACK(date, array, isref?, rows, avrg, rmax, isMax?)
)
);
which now use the function in order to combining the thunk evaluation with a sequence of aggregations
MAPϑ
= LAMBDA(arrayϑ, FNλ,
MAP(arrayϑ, LAMBDA(ϑ, FNλ(ϑ( ))))
);
I realise that this style of programming is not going mainstream anytime soon, but the fact that it is possible and appears to work well should be of interest.