Given an initial value and a unary LAMBDA function (or array of unary LAMBDA functions), apply each function sequentially to initial value; if iterations argument is provided, repeats the applications for that many iterations. Output is a table whose dimensions are [ROWS(funcs)*iterations]x[COLUMNS(funcs)].
Easiest way to provide an array of LAMBDAs is to use CHOOSE: CHOOSE({1,2,3},LAMBDA(x,...),LAMBDA(y,...),LAMBDA(z,...)). LAMBDAs in example are straight-forward, i.e. ADDTWO := LAMBDA(x,x+2), TIMESTHREE := LAMBDA(x,x*3)
Created to generalize sub-steps from AMORTIZE.
Easiest way to provide an array of LAMBDAs is to use CHOOSE: CHOOSE({1,2,3},LAMBDA(x,...),LAMBDA(y,...),LAMBDA(z,...)). LAMBDAs in example are straight-forward, i.e. ADDTWO := LAMBDA(x,x+2), TIMESTHREE := LAMBDA(x,x*3)
Created to generalize sub-steps from AMORTIZE.
Excel Formula:
=LAMBDA(init_value,funcs,[iterations],
LET(
fxns,IF(TYPE(funcs)=64,funcs,CHOOSE({1},funcs)),
iter,IF(ISOMITTED(iterations),1,iterations),
fxns_array,
MAKEARRAY(iter*ROWS(fxns),COLUMNS(fxns),
LAMBDA(i,j,INDEX(fxns,MOD(i-1,ROWS(fxns))+1,j))
),
SCAN(init_value,fxns_array,LAMBDA(acc,fn,fn(acc)))
)
)
LAMBDA_COMPOSE.xlsx | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | |||
1 | ||||||||||||||||||
2 | 2 | 1 | 3 | 9 | 1 | 3 | 9 | Balance | 100,000 | 100,000.00 | 100,416.67 | 91,855.92 | ||||||
3 | 3 | 10 | 7 | 14 | Rate | 5% | 91,855.92 | 92,238.65 | 83,677.90 | |||||||||
4 | 4 | 1 | 3 | 9 | 14 | 16 | 48 | Periods | 12 | 83,677.90 | 84,026.56 | 75,465.81 | ||||||
5 | 5 | 9 | 11 | 33 | 49 | 46 | 92 | 75,465.81 | 75,780.25 | 67,219.51 | ||||||||
6 | 6 | 33 | 35 | 105 | 92 | 94 | 282 | 67,219.51 | 67,499.59 | 58,938.84 | ||||||||
7 | 105 | 107 | 321 | 283 | 280 | 560 | 58,938.84 | 59,184.42 | 50,623.67 | |||||||||
8 | 321 | 323 | 969 | 560 | 562 | 1,686 | 50,623.67 | 50,834.60 | 42,273.85 | |||||||||
9 | 1,687 | 1,684 | 3,368 | 42,273.85 | 42,449.99 | 33,889.25 | ||||||||||||
10 | 3,368 | 3,370 | 10,110 | 33,889.25 | 34,030.45 | 25,469.70 | ||||||||||||
11 | 10,111 | 10,108 | 20,216 | 25,469.70 | 25,575.83 | 17,015.08 | ||||||||||||
12 | 17,015.08 | 17,085.97 | 8,525.23 | |||||||||||||||
13 | 8,525.23 | 8,560.75 | 0.00 | |||||||||||||||
SCAN |
Cell Formulas | ||
---|---|---|
Range | Formula | |
A2:A6 | A2 | =ACCUMULATE(1,LAMBDA(x,x+1),5) |
C2:E2 | C2 | =ACCUMULATE(1,CHOOSE({1,2,3},LAMBDA(x,x),ADDTWO,TIMESTHREE)) |
G2:I11 | G2 | =ACCUMULATE(1,CHOOSE({1,2,3;4,5,6},LAMBDA(x,x),ADDTWO,TIMESTHREE,ADDONE,MINUSTHREE,TIMESTWO),5) |
N2:P13 | N2 | =ACCUMULATE(balance*1,CHOOSE({1,2,3},LAMBDA(x,x),LAMBDA(x,x*(1+rate/12)),LAMBDA(x,x-PMT(rate/12,periods,-balance))),periods) |
C4:E8 | C4 | =ACCUMULATE(1,CHOOSE({1,2,3},LAMBDA(x,x),ADDTWO,TIMESTHREE),5) |
Dynamic array formulas. |
Named Ranges | ||
---|---|---|
Name | Refers To | Cells |
balance | =SCAN!$L$2 | N2 |
periods | =SCAN!$L$4 | N2 |
rate | =SCAN!$L$3 | N2 |
Upvote
0