HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //proc/thread-self/root/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/functions/reverse_each.rb
# Reverses the order of the elements of something that is iterable and optionally runs a
# [lambda](https://puppet.com/docs/puppet/latest/lang_lambdas.html) for each
# element.
#
# This function takes one to two arguments:
#
# 1. An `Iterable` that the function will iterate over.
# 2. An optional lambda, which the function calls for each element in the first argument. It must
#    request one parameter.
#
# @example Using the `reverse_each` function
#
# ```puppet
# $data.reverse_each |$parameter| { <PUPPET CODE BLOCK> }
# ```
#
# or
#
# ```puppet
# $reverse_data = $data.reverse_each
# ```
#
# or
#
# ```puppet
# reverse_each($data) |$parameter| { <PUPPET CODE BLOCK> }
# ```
#
# or
#
# ```puppet
# $reverse_data = reverse_each($data)
# ```
#
# When no second argument is present, Puppet returns an `Iterable` that represents the reverse
# order of its first argument. This allows methods on `Iterable` to be chained.
#
# When a lambda is given as the second argument, Puppet iterates the first argument in reverse
# order and passes each value in turn to the lambda, then returns `undef`.
#
# @example Using the `reverse_each` function with an array and a one-parameter lambda
#
# ```puppet
# # Puppet will log a notice for each of the three items
# # in $data in reverse order.
# $data = [1,2,3]
# $data.reverse_each |$item| { notice($item) }
# ```
#
# When no second argument is present, Puppet returns a new `Iterable` which allows it to
# be directly chained into another function that takes an `Iterable` as an argument.
#
# @example Using the `reverse_each` function chained with a `map` function.
#
# ```puppet
# # For the array $data, return an array containing each
# # value multiplied by 10 in reverse order
# $data = [1,2,3]
# $transformed_data = $data.reverse_each.map |$item| { $item * 10 }
# # $transformed_data is set to [30,20,10]
# ```
#
# @example Using `reverse_each` function chained with a `map` in alternative syntax
#
# ```puppet
# # For the array $data, return an array containing each
# # value multiplied by 10 in reverse order
# $data = [1,2,3]
# $transformed_data = map(reverse_each($data)) |$item| { $item * 10 }
# # $transformed_data is set to [30,20,10]
# ```
#
# @since 4.4.0
#
Puppet::Functions.create_function(:reverse_each) do
  dispatch :reverse_each do
    param 'Iterable', :iterable
  end

  dispatch :reverse_each_block do
    param 'Iterable', :iterable
    block_param 'Callable[1,1]', :block
  end

  def reverse_each(iterable)
    # produces an Iterable
    Puppet::Pops::Types::Iterable.asserted_iterable(self, iterable, true).reverse_each
  end

  def reverse_each_block(iterable, &block)
    Puppet::Pops::Types::Iterable.asserted_iterable(self, iterable).reverse_each(&block)
    nil
  end
end