Skip to content

Commit

Permalink
Accept block given to #merge
Browse files Browse the repository at this point in the history
This will allow greater control to the caller over whether to favor new items or old items.
  • Loading branch information
timriley committed Jun 26, 2022
1 parent 1fc9ad3 commit 299e25b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/dry/container/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,16 @@ def [](key)
# @return [Dry::Container::Mixin] self
#
# @api public
def merge(other, namespace: nil)
def merge(other, namespace: nil, &block)
if namespace
_container.merge!(
other._container.each_with_object(::Concurrent::Hash.new) do |a, h|
h[PREFIX_NAMESPACE.call(namespace, a.first, config)] = a.last
end
other._container.each_with_object(::Concurrent::Hash.new) { |(key, item), hsh|
hsh[PREFIX_NAMESPACE.call(namespace, key, config)] = item
},
&block
)
else
_container.merge!(other._container)
_container.merge!(other._container, &block)
end

self
Expand Down

0 comments on commit 299e25b

Please sign in to comment.