-
-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add @functorize #184
Add @functorize #184
Conversation
This looks great. Very elegant and easy to read. 👍 Am I right in understand that I shouldn't merge this until JuliaLang/julia#15804 is finished? |
@timholy Thanks. And yes, I'd like to adjust the version check before this is merged. I just wanted this to be ready and having received thumbs-up before JuliaLang/julia#15804 is merged so that affected packages don't have to wait too long for a strategy to handle the deprecations. Oh, and I probably should add something for |
28bf081
to
f54230c
Compare
Rebased, added README entry, added a few more cases (including Once JuliaLang/julia#15804 has been merged and the version check fixed, this should be done. |
3e85a00
to
b3fc658
Compare
export @functorize | ||
macro functorize(f) | ||
# TODO replace with proper condition on version once Julia#15804 is merged | ||
if VERSION >= v"0.5.0-" && !isdefined(Base, :BitFunctorUnary) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ready?
The new macro @functorize(f) turns function f into a Functor object if there is one in Base corresponding to f. E.g. @functorize(+) yields Base.AddFun(); @functorize(<) yields < in Julia 0.3, but Base.LessFun() in 0.4.
Note that `@functorize(centralizedabs2fun)` returns the type which can then be used to construct the actual functor as e.g. `@functorize(centralizedabs2fun)(23)`.
b3fc658
to
2aacc82
Compare
Updated the version check, so as long as the CI checks don't find some last-minute-errors I might have introduced, this should be good to merge. |
Very nice. Thanks much! |
The new macro
@functorize(f)
turns a functionf
into a functor object ifthere is one in Base corresponding to
f
. E.g.@functorize(+)
yieldsBase.AddFun()
;@functorize(<)
yields<
in Julia 0.3, butBase.LessFun()
in 0.4.
While at present this would more naturally be achieved by providing
LessFun
etc. in Compat, this PR is in anticipation of JuliaLang/julia#15804, which will deprecate all functors.Note that the version check in this PR can only be finalized once JuliaLang/julia#15804 has been merged.