Created
February 28, 2019 19:44
-
-
Save llowder/721560e9cb0b8cee4cfdde0df3e6e8c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function module::deep_sort( | |
Any $deep_sort, | |
) { | |
case $deep_sort { | |
Hash: { | |
$result = $deep_sort.keys.sort.map | Integer $index, String $key | { | |
$value = $deep_sort[$key].module::deep_sort | |
[$key, $value] | |
}.module::reduce_to_hash | |
} | |
Array: { | |
$result = $deep_sort.sort | |
} | |
default: { | |
$result = $deep_sort | |
} | |
} | |
$result | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Puppet::Functions.create_function(:'module::deep_sort') do | |
dispatch :deep_sort do | |
param 'Any', :collection | |
end | |
def deep_sort(collection) | |
if collection.is_a?(Hash) || colelction.is_a?(Array) | |
collection.deep_sort | |
else | |
collection | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment