Skip to content

Commit

Permalink
merge_strict simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
ivborissov committed Jul 11, 2023
1 parent 7a4bc0d commit e2e4ea7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# check keys in y before merge
function merge_strict(x::NamedTuple, y::NamedTuple)
y_indexes = indexin([keys(y)...], [keys(x)...])
y_lost = isnothing.(y_indexes)
@assert !any(y_lost) "Cannot merge elements with keys $(keys(y)[y_lost]) in strict mode."

kx = keys(x)
ky = keys(y)
for k in ky
@assert k in kx "Can't merge elements in strict mode. Key $k not found in $kx."
end
merge(x, y)
end

Expand Down

0 comments on commit e2e4ea7

Please sign in to comment.