Puppet Function: simplib::knockout

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

Overview

simplib::knockout(Array $array)Array

uses the knockout prefix of ‘–’ to remove elements from an array.

Examples:

Using knockout

array = [
  'ssh',
  'sudo',
  '--ssh',
]
result = simplib::knockout(array)

result => [
           'sudo'
          ]

Parameters:

  • array (Array)

    The array to knockout

Returns:

  • (Array)

    Resulting array.



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

function simplib::knockout(Array $array) {
  $included = $array.filter |$data| {
    $data !~ /^--/
  }

  $excluded_filter = $array.filter |$data| {
    $data =~ /^--/
  }
  $excluded = $excluded_filter.map |$data| {
    delete($data, '--')
  }

  ($included - $excluded)
}