Skip to content
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

Function Compositon with Pipe Operator #6607

Closed
aj0strow opened this issue Apr 23, 2014 · 4 comments
Closed

Function Compositon with Pipe Operator #6607

aj0strow opened this issue Apr 23, 2014 · 4 comments

Comments

@aj0strow
Copy link

Basically sugar, but would be cool to compose functions with the pipeline op. Could possibly help with #5571.

f(x) = x |> factor |> keys |> length

f = factor |> keys |> length
# ERROR: no method keys(Function,)
#  in |> at operators.jl:159

I think the relevant code is

|>(x, f::Function) = f(x)
.

Something like this?

|>(f1::Function, f2:Function) = x -> f1(f2(x))

Down to figure out how to write a test n such, just let me know.

@simonbyrne
Copy link
Contributor

I was thinking about this the other day, the problem would be how to distinguish between f1(f2) (i.e. f1 acts on a function f2), and x -> f1(f2(x)) (the composition of f1 and f2).

I agree it would be useful though, especially if there was a way to combine all this with the do notation.

@stevengj
Copy link
Member

you can do x -> x |> factor |> keys |> length

@stevengj
Copy link
Member

This seems to be a duplicate of #5236.

@aj0strow
Copy link
Author

Indeed a duplicate. Sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants