Puppet Function: sendmail::canonify_array

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

Summary

Canonify an array

Overview

sendmail::canonify_array(Array[String] $arg)Array[String]

Rewrite the input array the following way:

  • strip spaces from the beginning and end of each string

  • remove duplicate entries

  • sort the result

Parameters:

  • arg (Array[String])

    array of strings to canonify

Returns:

  • (Array[String])

    array of canonified strings



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'functions/canonify_array.pp', line 13

function sendmail::canonify_array(Array[String] $arg) >> Array[String] {
  # strip items and set to undef if empty
  $sparse_array = Array($arg).map |$item| {
    $stripped_item = strip($item)

    empty($stripped_item) ? {
      true    => undef,
      default => $stripped_item,
    }
  }

  # remove empty items from array
  $filtered_array =  $sparse_array.filter |$item| { !empty($item) }

  # sort result and filter duplicates
  unique(sort($filtered_array))
}