Forum Discussion
PeterBartholomew1
Dec 24, 2021Silver Contributor
Accumulating arrays
Spreadsheets are the home of the 2D array. On closer examination most of the 2D arrays that one sees are actually 'arrays of arrays', that is a 1D array nested within a list of similar arrays. At p...
PeterBartholomew1
Dec 30, 2021Silver Contributor
Thank you so much. With your guidance and example I think I have achieved what I set out to do!
The formula I now have is
= LAMBDA(arr,init,Fnλ,
LET(
arrϑ, BYCOL(arr, THUNKλ),
initϑ, THUNKλ(init),
accumulatedϑ, SCAN(initϑ, arrϑ, Fnλ),
EXPANDTHUNKλ(accumulatedϑ)
)
)(array,initial,ADDTHUNKλ)
The main difference from our earlier work is that I converted columns into thunks so that I could feed a row array of thunks into SCAN. That makes the Lambda parameter a little more complicated, but allows the rows to be processed together.
By changing the parameter string to
(growth,invested,GROWTHTHUNKλ)
&
(array,FibInit,FIBTHUNKλ)
respectively the same anonymous Lambda function performed a growth calculation and, as a party piece, evaluated terms of the Fibonacci series.
The supporting Lambda functions were
"THUNKλ"
= LAMBDA(x,LAMBDA(x))
"EXPANDTHUNKλ"
= LAMBDA(aϑ,
MAKEARRAY(COUNTA(INDEX(aϑ,1)()),COUNTA(aϑ),
LAMBDA(r,c,INDEX(INDEX(aϑ,c)(),r))
)
)
"ADDTHUNKλ"
= LAMBDA(accϑ,vϑ, THUNKλ(accϑ()+vϑ()))
"GROWTHTHUNKλ"
= LAMBDA(accϑ,vϑ, THUNKλ(accϑ()*(1+vϑ())))
"FIBTHUNKλ"
= LAMBDA(accϑ,vϑ, THUNKλ(MMULT(M, accϑ())))