Class: Array

Inherits:
Object show all
Defined in:
lib/classifier/extensions/vector.rb

Instance Method Summary collapse

Instance Method Details

#sum_with_identity(identity = 0.0) ⇒ Object



12
13
14
15
16
17
# File 'lib/classifier/extensions/vector.rb', line 12

def sum_with_identity(identity = 0.0, &)
  return identity unless size.to_i.positive?
  return map(&).sum_with_identity(identity) if block_given?

  compact.reduce(identity, :+).to_f
end