This is possible, and in several cases (e.g. ==) we already do this. However, in a multi-argument function it’s often not clear what argument you would want to “functionalize” (i.e. “curry”).
I think functions like reshape, map, filter, reduce, + operator, etc, can be made functional without ambiguity.
Is this code good or there are bad practices?
Base.reshape(dim::Tuple) = x -> Base.reshape(x, dim) # if the function takes the dimension
Base.reshape(array) = x -> Base.reshape(array, x) # if the function takes the array
Thank you, but I don’t like custom solutions with macros and I don’t want that who reads my code must know too many libraries.
Thank you, but I don’t like a reshape inside another reshape. I would like to use a more elegant style with pipe operator.
An alternative, if you don’t like the nested reshapes but need to repeat this pattern several times, is to stick it into a function – so that at least your code has it only once. I think this is quite readable:
Thanks for the answers, I found out a lot of new things I didn’t know.
Before asking this question I thought that a more functional style was more elegant and less prone to errors.
Now I find out that there are several problems with this functional approach.
At this point I’m wondering: how popular is the pipe operator?
Does it make sense to have a more functional style?
Sorry for my English, I’m using an automatic translator.
No, I’m not trying to convince you to use reshape for this purpose. I’m saying that if you use reshape for anything, you can use : instead of length(x). It is more elegant.