-
Notifications
You must be signed in to change notification settings - Fork 55
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 function composition #299
Comments
Yes and the thing is that |
Actually I had implemented something like that back in 2019 before you cleaned up the package. FWIW, here are the functions I had written: """Check whether expression is a single-argument call, like f(x)"""
isoneargcall(e::Expr) =
e.head === :call && length(e.args) == 2 && e.args[1] isa Symbol
function tocomposition(body)
if body.head == :(=) && length(body.args) == 2 &&
body.args[2] isa Expr
funs = Symbol[]
e = body.args[2]
while e isa Expr && isoneargcall(e)
push!(funs, e.args[1])
e = e.args[2]
end
if e isa Symbol || (e isa QuoteNode && e.value isa Symbol)
# Recursion parsed the full expression
return mapreduce(eval, ∘, funs)
else # Expression doesn't consist only in single-argument calls
return body
end
end
return body
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think that when we see
fun1(fun2(x))
the function passed totransform
should befun1 \circ fun2
. That way we can take advantage of more fast paths iirc.The text was updated successfully, but these errors were encountered: