Class: Alf::Aggregator::Sum

Inherits:
Alf::Aggregator show all
Defined in:
lib/alf/aggregator/sum.rb

Overview

Defines a `sum()` aggregation operator.

Example:

# direct ruby usage
Alf::Aggregator.sum{ qty }.aggregate(...)

# lispy 
(summarize :supplies, [:sid], :total => sum{ qty })

Instance Attribute Summary

Attributes inherited from Alf::Aggregator

#functor, #options, #source

Instance Method Summary collapse

Methods inherited from Alf::Aggregator

#==, #aggregate, coerce, #default_options, #finalize, #happens, #has_source_code!, #infer_type, inherited, #initialize, #to_lispy

Methods included from Support::Registry

#each, #listen, #listeners, #register, #registered

Constructor Details

This class inherits a constructor from Alf::Aggregator

Instance Method Details

#_happens(memo, val) ⇒ Object

Aggregates on a tuple occurence through `memo + val`

See Also:

  • Aggregator::InstanceMethods#_happens

26
27
28
# File 'lib/alf/aggregator/sum.rb', line 26

def _happens(memo, val) 
  memo + val
end

#leastObject

Returns 0 as least value.

See Also:

  • Aggregator::InstanceMethods#least

19
20
21
# File 'lib/alf/aggregator/sum.rb', line 19

def least()
  0
end