Function to compare hashes #22
Closed
XMol
started this conversation in
Show and tell
Replies: 2 comments 4 replies
-
I'm surprised you didn't contribute your functions to stdlib. |
Beta Was this translation helpful? Give feedback.
4 replies
-
Credits to @smortex, who proposed a solution that a accomplishes the comparison of two Hashes without adding a new function to Puppet: compare($hash1.dig('primary_key'), $hash2.dig('primary_key')) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Puppet is incapable of comparing two hashes with each other and I'm very surprised that there is no function in the stdlib tool set to address that either. A function like this seems quite simple to me:
Given a lambda that transforms a Hash into something that Ruby can compare with
<=>
, arbitrary Hashes can be compared to each other. If no lambda is given, the functions falls back to casting both Hashes to sorted Arrays and then compare them (which Ruby can do already).Examples
Now it is also possible to order an Array of Hashes with the built-in
sort()
function:Beta Was this translation helpful? Give feedback.
All reactions