Skip to content

Instantly share code, notes, and snippets.

@ncalm
Last active April 14, 2024 12:51
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ncalm/ef7ed953571eec1475c291948aa2dbc3 to your computer and use it in GitHub Desktop.
Save ncalm/ef7ed953571eec1475c291948aa2dbc3 to your computer and use it in GitHub Desktop.
stacker namespace for Lambda
/*
array is a column of stuff to which we want to apply element function
row_function is some function that produces an array with a fixed number of columns
the column count produced by row_function must be identical regardless of input
stack_function is one of V or H
If you're unsure how these work or why we would use them, please review these videos:
https://youtu.be/04jOeiMypXw
https://youtu.be/wEBLT9QfQRw
*/
V = LAMBDA(one, two, VSTACK(one, two));
H = LAMBDA(one, two, HSTACK(one, two));
STACKER = LAMBDA([stack_function],
LAMBDA(row_function,
LAMBDA(array,
LET(
_stack_function, IF(ISOMITTED(stack_function), V, stack_function),
seq, SEQUENCE(ROWS(array)),
firstrow, row_function(INDEX(array,1,)),
reducer, REDUCE(
firstrow,
DROP(seq, 1),
LAMBDA(acc, curr,
LET(thisrow, INDEX(array,curr,), _stack_function(acc, row_function(thisrow)))
)
),
reducer
)
)
)
);
VSTACKER = STACKER(V);
HSTACKER = STACKER(H);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment