HEX
Server: Apache
System: Linux dinesh8189 5.15.98-grsec-sharedvalley-2.lc.el8.x86_64 #1 SMP Thu Mar 9 09:07:30 -03 2023 x86_64
User: cgmgerenciamento1 (814285)
PHP: 8.1.26
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: //opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/functions/partition.rb
# frozen_string_literal: true

# Returns two arrays, the first containing the elements of enum for which the block evaluates to true,
# the second containing the rest.
Puppet::Functions.create_function(:partition) do
  # @param collection A collection of things to partition.
  # @example Partition array of empty strings, results in e.g. `[[''], [b, c]]`
  #   ```puppet
  #   ['', b, c].partition |$s| { $s.empty }
  #   ```
  # @example Partition array of strings using index, results in e.g. `[['', 'ab'], ['b']]`
  #   ```puppet
  #   ['', b, ab].partition |$i, $s| { $i == 2 or $s.empty }
  #   ```
  # @example Partition hash of strings by key-value pair, results in e.g. `[[['b', []]], [['a', [1, 2]]]]`
  #   ```puppet
  #   { a => [1, 2], b => [] }.partition |$kv| { $kv[1].empty }
  #   ```
  # @example Partition hash of strings by key and value, results in e.g. `[[['b', []]], [['a', [1, 2]]]]`
  #   ```puppet
  #   { a => [1, 2], b => [] }.partition |$k, $v| { $v.empty }
  #   ```
  dispatch :partition_1 do
    required_param 'Collection', :collection
    block_param 'Callable[1,1]', :block
    return_type 'Tuple[Array, Array]'
  end

  dispatch :partition_2a do
    required_param 'Array', :array
    block_param 'Callable[2,2]', :block
    return_type 'Tuple[Array, Array]'
  end

  dispatch :partition_2 do
    required_param 'Collection', :collection
    block_param 'Callable[2,2]', :block
    return_type 'Tuple[Array, Array]'
  end

  def partition_1(collection)
    collection.partition do |item|
      yield(item)
    end.freeze
  end

  def partition_2a(array)
    partitioned = array.size.times.zip(array).partition do |k, v|
      yield(k, v)
    end

    partitioned.map do |part|
      part.map { |item| item[1] }
    end.freeze
  end

  def partition_2(collection)
    collection.partition do |k, v|
      yield(k, v)
    end.freeze
  end
end