Last active
April 16, 2024 23:54
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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