Skip to content

Instantly share code, notes, and snippets.

@ncalm
Last active April 16, 2024 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncalm/d00a84ee30e474b5ed5e97a77975fdce to your computer and use it in GitHub Desktop.
Save ncalm/d00a84ee30e474b5ed5e97a77975fdce to your computer and use it in GitHub Desktop.
This Excel LAMBDA function mimics argument unpacking for arbitrary functions of up to 5 parameters
// Spread an array of arguments across the parameters of a function of up to five parameters
SPREAD = LAMBDA(function, LAMBDA(arg_array,
LET(
arg_vector, TOCOL(arg_array),
CHOOSE(
ROWS(arg_vector),
function(INDEX(arg_vector,1)),
function(INDEX(arg_vector,1), INDEX(arg_vector, 2)),
function(INDEX(arg_vector,1), INDEX(arg_vector, 2), INDEX(arg_vector, 3)),
function(INDEX(arg_vector,1), INDEX(arg_vector, 2), INDEX(arg_vector, 3), INDEX(arg_vector, 4)),
function(INDEX(arg_vector,1), INDEX(arg_vector, 2), INDEX(arg_vector, 3), INDEX(arg_vector, 4), INDEX(arg_vector, 5)),
// Add more lines if necessary
)
)
));
//Usage examples
// For B1={2024, 4, 16}
// =SPREAD(DATE)(B1#);
// For a multi-row array of year, month, day in B1
// =BYROW(B1#, SPREAD(DATE));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment