-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Enable |> to create a function when given of two. #5236
Conversation
That means, f |> g creates a function which, when applied, first applies f to its arguments and then g to the result of f. This is very useful to create functions for map/filter: map(sin, map(cos, map(sqrt, [1 2 3]))) or map((x)->sin(cos(sqrt(x))), [1 2 3]) become map(sqrt |> cos |> sin, [1 2 3]) which is much more readable imo. And for a real-world use: map((fname)->float32(imread(fname)), image_filenames) becomes map(imread |> float32, image_filenames)
Cool. But I wonder if you haven't gone too far enough? I find myself defining
But I haven't found a generic way to do it. Also, in my dreams it would be lazy rather than |
I'm not convinced of the usefulness of this method in general, since the notation is nonstandard and it is very easy to define it yourself in your own code. |
There is already a bit of a convention that x |> f does f(x).
|
@jiahao @JeffBezanson Yes, I didn't invent this, just extended the "builtin" @gitfoxi yeah, it being lazy would be cool, but I think that needs a whole different machinery. |
I think it is too confusing for an operator to mean application some times
|
To me they feel the same: In the end, Now, I do get your point, and if you think it's too confusing for most people or doesn't fit julia, so be it :) |
Type-based dispatch is simply not appropriate here, because a function can |
You wouldn't like Alonzo when he's mad. |
Aw Closed. We were having such a nice circle jerk. On Thu, Dec 26, 2013 at 1:14 PM, Stefan Karpinski
Michael |
That means,
f |> g
creates a function which, when applied, firstapplies f to its arguments and then g to the result of f. This is very
useful to create functions for map/filter:
or
become
which is much more readable imo.
And for a real-world use:
becomes