julia
julia copied to clipboard
getproperty(x)
It would be convenient to add
getproperty(sym) = x -> getproperty(x, sym)
so I can use map(getproperty(:val), xs).
It's slightly more verbose, but Base.Fix2(getproperty,sym) is equivalent to your proposed getproperty(sym) definition and has some compiler advantages - plus you can use it right now. The Base.Fix1 and Base.Fix2 types are how most of these curried functions are constructed.
Especially for functions where it isn't obvious whether the one-argument version should curry the first or second argument, we tend not to define a one-argument variant. However, I expect that getproperty would typically be curried as you have done here, so it would be a candidate for inclusion.
If you're interested in this feature, this would not be a difficult PR for you to create. Then you wouldn't have to rely on someone else being motivated enough to make one.
I can imagine many other functions for which one might want to have a currying version like you say. We already have a currying ==(x) or in(x) for specially useful/frequently used functions (via the Fix2 wrapper). I guess what you would need is to make a strong case why your code pattern is sufficiently frequent and useful to make getproperty a member of the VIP currying club in Base, as compared to any other two-argument function.
(Note, moreover, that you can trivially add your desired definition to your session or package, so you don't need to convince anyone: just roll your own!)
@jariji, you may be interested in weighing in on the PR Ive linked to this issue.