Method: FunRuby::Hash#merge

Defined in:
lib/fun_ruby/hash.rb

#merge(first = F._, second = F._) ⇒ Hash

Merges two hashes. The key-value pairs from the second to the first. If the key is already taken the current value will be replaced.

Examples:

Base

first = { name: "John" }
second = { age: 20 }
F::Hash.merge(first, second) # => { name: "John", age: 20 }

first = { name: "John" }
second = { name: "Bill", age: 20 }
F::Hash.merge(first, second) # => { name: "Bill", age: 20 }

Curried

first = { name: "John" }
second = { age: 20 }
curried = F::Hash.merge
curried.(first).(second) # => { name: "John", age: 20 }

first = { name: "John" }
second = { name: "Bill", age: 20 }
curried = F::Hash.merge
curried.(first).(second) # => { name: "Bill", age: 20 }

Curried with placeholders

first = { name: "John" }
second = { age: 20 }
curried = F::Hash.merge(F._, F._)
curried.(first).(second) # => { name: "John", age: 20 }

first = { name: "John" }
second = { name: "Bill", age: 20 }
curried = F::Hash.merge(F._, second)
curried.(first) # => { name: "Bill", age: 20 }

Parameters:

  • first (#to_h) (defaults to: F._)
  • second (#to_h) (defaults to: F._)

Returns:

Since:

  • 0.1.0



193
194
195
# File 'lib/fun_ruby/hash.rb', line 193

def merge(first = F._, second = F._)
  curry_implementation(:merge, first, second)
end