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