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

Splat #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ function insert_first_arg(e::Expr, firstarg; assignment = false)
elseif head == :call && length(args) > 0
if length(args) ≥ 2 && Meta.isexpr(args[2], :parameters)
Expr(head, args[1:2]..., firstarg, args[3:end]...)
elseif args[1] == :splat
Expr(:call, args[2], Expr(:..., firstarg))
elseif Meta.isexpr(args[1], :call) && args[1].args[1] == :splat
Expr(:call, args[1].args[2], Expr(:..., firstarg), args[2:end]...)
else
Expr(head, args[1], firstarg, args[2:end]...)
end
Expand Down Expand Up @@ -278,8 +282,16 @@ function replace_underscores(expr::Expr, replacement)
# for all other expressions, their arguments are checked for underscores recursively
# and replaced if any are found
else
is_splat = false
if !isempty(expr.args) && expr.args[1] isa Expr && expr.args[1].args[1] == :splat
is_splat = true
replacement = Expr(:..., replacement)
end
newargs = map(x -> replace_underscores(x, replacement), expr.args)
found_underscore = any(first.(newargs))
if is_splat && found_underscore
newargs[1] = (newargs[1][1], expr.args[1].args[2])
end
newexpr = Expr(expr.head, last.(newargs)...)
end
return found_underscore, newexpr
Expand Down