-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 Returns #39794
add Returns #39794
Conversation
|
Are there any cases where this is helpful in Base code itself? |
Would it be too much of a pun to define this using |
I think so. A pattern which I personally use often is Line 302 in e32e94e
Another one is Line 1311 in e32e94e
So I estimate, there is probably > 100 places in julia where |
We can use another name of course. Names that came to my mind were |
Common lisp calls this |
Suggestion from triage: call it |
Sounds good. So this means triage is in favor of adding this functionality? |
Co-authored-by: Jeff Bezanson <[email protected]>
I changed most of the constant lambdas in Base and test into Returns. From my point of view, this PR is ready. |
bump |
Co-authored-by: Simeon Schaub <[email protected]>
Bunp |
Was |
It was mentioned above but not discussed further I think. |
So how to move forward from here? Should this be renamed from |
|
I'm amused by how every usage of this made the code longer. I suppose the advantage is that |
@StefanKarpinski in general the main selling points of |
I too was skeptical about this initially, but then immediately found myself wanting to use it for DataStructure.jl's DefaultDict, which calls |
That does seem odd—are you storing a function in the dictionary (certainly possible), or do you mean |
Yes, I was storing a transformer function in a dict. Type stability is overrated. :) |
This also has an advantage when the value might be expensive to compute, e.g. |
This PR adds
Always
Returns
which represents "constant" functions. So instead of writingyou can do
f = Returns(42)
.Benefits are:
Returns
:instead of