julia icon indicating copy to clipboard operation
julia copied to clipboard

getproperty(x)

Open jariji opened this issue 3 years ago • 2 comments

It would be convenient to add

getproperty(sym) = x -> getproperty(x, sym)

so I can use map(getproperty(:val), xs).

jariji avatar Sep 20 '22 01:09 jariji

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.

mikmoore avatar Sep 20 '22 14:09 mikmoore

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!)

pablosanjose avatar Sep 21 '22 08:09 pablosanjose

@jariji, you may be interested in weighing in on the PR Ive linked to this issue.

Tokazama avatar Sep 24 '22 05:09 Tokazama