Puppet Function: network::compact_hash

Defined in:
functions/compact_hash.pp
Function type:
Puppet Language

Summary

Compresses a hash by removing all elements whose values are `undef`

Overview

network::compact_hash(Hash $hash) ⇒ Hash

Examples:

$example = {
  'one'  => 'two',
  'red'  => undef,
}

network::compact_hash($example)
# => { 'one => 'two' }

Parameters:

  • hash (Hash) —

    The hash to compact

Returns:

  • (Hash) —

    A new hash with all ‘undef` values removed



13
14
15
16
# File 'functions/compact_hash.pp', line 13

function network::compact_hash(Hash $hash) >> Hash {
  # Use the built-in `filter` function to remove all elements with `undef` values
  $hash.filter |$key, $value| { $value != undef }
}