Created
April 15, 2024 23:29
-
-
Save ncalm/b91c72d0865a99f0cf8a47cb8ff94a6e to your computer and use it in GitHub Desktop.
Excel LAMBDA examples of function chaining
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
IFOMITTED = LAMBDA(arg, then, IF(ISOMITTED(arg), then, arg)); | |
// Functions for common mathematical operators | |
MULTIPLY = LAMBDA(x, y, x*y); | |
ADD = LAMBDA(x, y, x+y); | |
SUBTRACT = LAMBDA(x, y, x-y); | |
DIVIDE = LAMBDA(x, y, x/y); | |
// Apply a series of functions to an array | |
PIPE =LAMBDA(array, functions, operator, [init], | |
REDUCE(IFOMITTED(init, array), functions, LAMBDA(a, b, operator(a , b(array)))) | |
); | |
// Currently arrays of functions are composed with HSTACK or VSTACK | |
pipe_usage_example | |
=PIPE( | |
SEQUENCE(10), | |
HSTACK(LAMBDA(x, MAX(x)), LAMBDA(x, SUM(x))), | |
MULTIPLY, | |
1 | |
); | |
/* Typed arrays would simplify this dramatically | |
Additionally, allowing passage of mathematical operators | |
as functions (3rd arg) would be huge! */ | |
/* | |
//This doesn't work! | |
dream_pipe_usage_example =PIPE(SEQUENCE(10), {MAX, SUM}, *, 1); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment