Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Jul 17, 2023
1 parent dcf2356 commit 70bbb46
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/simulations/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ function new_args(agent::A, model; kwargs...) where {A<:AbstractAgent}
if isempty(kwargs)
new_args = map(x -> deepcopy(getfield(agent, x)), fields_no_id)
else
kwargs_ntuple = NamedTuple(kwargs)
new_args = map(x -> hasproperty(kwargs_ntuple, x) ?
deepcopy(kwargs_ntuple[x]) : deepcopy(getfield(agent, x)),
fields_no_id)
kwargs_nt = NamedTuple(kwargs)
new_args = map(x -> choose_arg(x, kwargs_nt, agent), fields_no_id)
end
end

function choose_arg(x, kwargs_nt, agent)
return deepcopy(getfield(hasproperty(kwargs_nt, x) ? kwargs_nt : agent, x))
end

0 comments on commit 70bbb46

Please sign in to comment.