bartavelle / language-puppet

A library to work with Puppet manifests, test them and eventually replace everything ruby.
BSD 3-Clause "New" or "Revised" License
51 stars 8 forks source link

stdlib :: merge more than two hash #159

Closed jfroche closed 8 years ago

jfroche commented 8 years ago

We have the usecase to merge more than two hash (3 in fact)

merge :: [PValue] -> InterpreterMonad PValue
merge [PHash a, PHash b] = return (PHash (b `HM.union` a))
merge [a,b] = throwPosError ("merge(): Expects two hashes, not" <+> pretty a <+> pretty b)
merge _ = throwPosError "merge(): Expects two hashes"

can you do the same for 3 hash or even better merge an infine list of PHash ?

ruby implementation is here: https://github.com/puppetlabs/puppetlabs-stdlib/blob/master/lib/puppet/parser/functions/merge.rb

bartavelle commented 8 years ago

Just pushed a fix. Do you mind checking of its behavior is consistent with how puppet works (with regards to key collisions) ?

jfroche commented 8 years ago

I will look with @PierreR to add a unittest for this one

bartavelle commented 8 years ago

I copied the unit tests from Puppet and found a regression. This is now fixed.