Sha256: e0b281ab286ae9f76049f18a7748d034df2d1b0b093c471754e7fa65bf62c649

Contents?: true

Size: 1.77 KB

Versions: 50

Compression:

Stored size: 1.77 KB

Contents

Puppet::Parser::Functions::newfunction(
  :filter,
  :arity => -3,
  :doc => <<-DOC
 Applies a parameterized block to each element in a sequence of entries from the first
 argument and returns an array or hash (same type as left operand for array/hash, and array for
 other enumerable types) with the entries for which the block evaluates to `true`.

 This function takes two mandatory arguments: the first should be an Array, a Hash, or an
 Enumerable object (integer, Integer range, or String),
 and the second a parameterized block as produced by the puppet syntax:

       $a.filter |$x| { ... }
       filter($a) |$x| { ... }

 When the first argument is something other than a Hash, the block is called with each entry in turn.
 When the first argument is a Hash the entry is an array with `[key, value]`.

 Example Using filter with one parameter

       # selects all that end with berry
       $a = ["raspberry", "blueberry", "orange"]
       $a.filter |$x| { $x =~ /berry$/ }          # rasberry, blueberry

 If the block defines two parameters, they will be set to `index, value` (with index starting at 0) for all
 enumerables except Hash, and to `key, value` for a Hash.

Example Using filter with two parameters

     # selects all that end with 'berry' at an even numbered index
     $a = ["raspberry", "blueberry", "orange"]
     $a.filter |$index, $x| { $index % 2 == 0 and $x =~ /berry$/ } # raspberry

     # selects all that end with 'berry' and value >= 1
     $a = {"raspberry"=>0, "blueberry"=>1, "orange"=>1}
     $a.filter |$key, $x| { $x =~ /berry$/ and $x >= 1 } # blueberry

- since 3.4 for Array and Hash
- since 3.5 for other enumerables
- note requires `parser = future`
DOC
) do |args|
  function_fail(["filter() is only available when parser/evaluator future is in effect"])
end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/filter.rb
puppet-3.8.7 lib/puppet/parser/functions/filter.rb
puppet-3.8.7-x86-mingw32 lib/puppet/parser/functions/filter.rb
puppet-3.8.7-x64-mingw32 lib/puppet/parser/functions/filter.rb
puppet-3.8.6 lib/puppet/parser/functions/filter.rb
puppet-3.8.6-x86-mingw32 lib/puppet/parser/functions/filter.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/filter.rb
puppet-3.8.6-x64-mingw32 lib/puppet/parser/functions/filter.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/filter.rb
puppet-3.8.5 lib/puppet/parser/functions/filter.rb
puppet-3.8.5-x86-mingw32 lib/puppet/parser/functions/filter.rb
puppet-3.8.5-x64-mingw32 lib/puppet/parser/functions/filter.rb
puppet-3.8.4 lib/puppet/parser/functions/filter.rb
puppet-3.8.4-x86-mingw32 lib/puppet/parser/functions/filter.rb
puppet-3.8.4-x64-mingw32 lib/puppet/parser/functions/filter.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/filter.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/filter.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/filter.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/filter.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/filter.rb