Puppet Function: sendmail::canonify_array

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

Overview

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

canonify_array.pp — Canonify an array

The function expects an array of strings as input. It rewrites 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])

Returns:

  • (Array[String])


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'functions/canonify_array.pp', line 9

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))
}