Sha256: e32fb3ae5636f0413fe8a1580e7610c899d51d8bc01d065caf63c48c9b6b1732

Contents?: true

Size: 817 Bytes

Versions: 16

Compression:

Stored size: 817 Bytes

Contents

Puppet::Functions.create_function(:reduce) do

  dispatch :reduce_without_memo do
    param 'Any', :enumerable
    block_param 'Callable[2,2]', :block
  end

  dispatch :reduce_with_memo do
    param 'Any', :enumerable
    param 'Any', :memo
    block_param 'Callable[2,2]', :block
  end

  def reduce_without_memo(enumerable)
    enum = asserted_enumerable(enumerable)
    enum.reduce {|memo, x| yield(memo, x) }
  end

  def reduce_with_memo(enumerable, given_memo)
    enum = asserted_enumerable(enumerable)
    enum.reduce(given_memo) {|memo, x| yield(memo, x) }
  end

  def asserted_enumerable(obj)
    unless enum = Puppet::Pops::Types::Enumeration.enumerator(obj)
      raise ArgumentError, ("#{self.class.name}(): wrong argument type (#{obj.class}; must be something enumerable.")
    end
    enum
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
puppet-retrospec-1.8.0 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-1.7.0 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-1.6.1 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-1.6.0 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-1.5.0 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-1.4.1 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-1.4.0 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-1.3.2 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-1.3.1 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-1.3.0 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-1.2.1 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-1.2.0 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-1.1.0 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-1.0.0 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-0.12.1 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb
puppet-retrospec-0.12.0 spec/fixtures/fixture_modules/sample_module/lib/puppet/functions/reduce.rb