last day (24 days later) » 

6:55 AM
1
A: On Google Sheets (and only built-in functions allowed, no Google Apps Script) Is it possible to simulate pipe function?

bricks96I was able to mostly recreate the LAMB namespace that's explained on this site Excel Lambda Introducing the LAMB Namespace. I called it PIPER and added some logging and helper functionality. The latest version can be found here. (PIPER) LAMBDA(Names,Initial, LET(SQRT_,LAMBDA(vector,INDEX(SQRT(v...

 
I have a feeling this answer is legendary even though I still working on reading it. I hope you do not mind me finishing reading it first before I mark any answer as selected! Just want to say thank you in advance! Knowing there are someone caring about this issue is very encouraging!
Even though the key concept you provided is similar to the friend below, using an array of function names rather than an array of functions, I still get inspired in some ways. I like how you simulate namespace (or OOP), which makes more sense to have a kinda registering list of function names because it helps with distinguishing public methods from private ones.
However, the solution you guys provided seems to justify that we do not have a way wrapping functions in an array and unwrap it to get the very same functions insides (You may try TYPE(CHOOSECOLS({LAMBDA(x ,x)}, 1)) and it returns 16, representing an error ). it is kinda frustrating but I guess it is about the the deep structure of array Google Sheets provides... I learned a lot from this discussion though. Thanks a lot, guys!
 
If you look at the functions being used in PIPER, you'll see TRIPLE. That was a separate named function that I created. So yes, you do need to have them "registered" as part of the function, but they don't need to be defined within PIPER. But in the second example, both the array of triggers (similar to the array of names) and the CHOOSER function are passed in as parameters with no set size.
 
I noticed that you make function names and piper function independent! It is also acceptable if I have to put function names in a function like your LAMB in case I try to separate them as an OOP approach, which is also intriguing as well! However, since here I am working on FP, I am still eager to know how to pass an array of functions (umm, maybe function names are still acceptable if they don't require to be registered in advance anywhere). Discussion above makes me feel it is impossible for now, though.
I still want to mark your answer as selected, because it is a very nice discussion! Hopefully one day Google Sheets will allow us to have a genuine array of functions, without executing them before unwrapped like a brat on Christmas' Eve.
 
Would you say that LAMBDA(id, CHOOSE(id, <lambda1>, <lambda2>, ...)) acts as an array of functions? You give it an index number and it returns that corresponding function.
 
It is truly a good question, even though it acts more like a method that picks up an item but its index in an array, but I guess I know what you are talking about. The inconvenient part is that to simulate a genuine array of functions with this CHOOSER still requires us to put function names in an array, which we map to get the indices as input of the CHOOSER function.
I was seriously wondering whether I should wrap all the functions I need in the CHOOSER function hahaha, but I would say it is really like we are trying to mimic operation of computer memory (registering a variable name for function is what we are doing here, isn't it?), which is not a user of application is supposed to do. I am not complaining though. I love Google Sheets. Knowing the possible limit makes me happy. : )
And thank you, bricks96. It is a lovely conversation! I enjoy the process of inquiry and exploration accompanied by you. I have been inspired a lot.
 
6:55 AM
As long as you know the order of the functions in your CHOOSER, the you don't need to use the names. I just took the LET function definitions and created a named function, MY_SPACE, that returns this function: LAMBDA(id,CHOOSE(id,SQRT_,LN_,LOG_...)). Now, in a formula, I can say LET(lamb,MY_SPACE(), lamb(1)(25)) will return the SQRT(25) because that's the function associated with index 1. How else were you planning to refer to your formulas or did you just want to call them sequentially?
The function names were actually an afterthought to help the user out when referring to the functions instead of always using index values.
Here's a link to the sheet where I created that MY_SPACE version.
 
 
7 hours later…
1:30 PM
Hi Bricks! I am not familiar with how to socialize with people on stackoverflow hahaha
I suppose it is like a private space here?
 
1:41 PM
I still want my script (complex formulas) is semantically meaningful, though. It seems that the best way we have now is to make PIPE function like
```
LAMBDA(input, REDUCE(input, {1, 2}, LAMBDA(output, idx, CHOOSE(idx, plusOne, multTwo)(output))))
```
However, it still does not look like a common pipe function, which is supposed to be like:
```
pipe(plusOne, multTwo)()
```
 

  last day (24 days later) »