Skip to content

Instantly share code, notes, and snippets.

@llowder
Created February 28, 2019 19:44
Show Gist options
  • Save llowder/721560e9cb0b8cee4cfdde0df3e6e8c8 to your computer and use it in GitHub Desktop.
Save llowder/721560e9cb0b8cee4cfdde0df3e6e8c8 to your computer and use it in GitHub Desktop.
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
}
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