Class: Alf::Aggregator::Avg
- Inherits:
-
Alf::Aggregator
- Object
- Alf::Aggregator
- Alf::Aggregator::Avg
- Defined in:
- lib/alf/aggregator/avg.rb
Overview
Defines a ‘avg()` aggregation operator.
Example:
# direct ruby usage
Alf::Aggregator.avg{ qty }.aggregate(...)
# lispy
(summarize :supplies, [:sid], :avg => avg{ qty })
Instance Attribute Summary
Attributes inherited from Alf::Aggregator
Instance Method Summary collapse
-
#_happens(memo, val) ⇒ Object
Aggregates on a tuple occurence.
-
#finalize(memo) ⇒ Object
Finalizes the computation.
-
#least ⇒ Object
Returns [0.0, 0.0] as least value.
Methods inherited from Alf::Aggregator
#==, #aggregate, coerce, #default_options, #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.
26 27 28 |
# File 'lib/alf/aggregator/avg.rb', line 26 def _happens(memo, val) [memo.first + val, memo.last + 1] end |
#finalize(memo) ⇒ Object
Finalizes the computation.
33 34 35 |
# File 'lib/alf/aggregator/avg.rb', line 33 def finalize(memo) memo.first / memo.last end |
#least ⇒ Object
Returns [0.0, 0.0] as least value.
19 20 21 |
# File 'lib/alf/aggregator/avg.rb', line 19 def least() [0.0, 0.0] end |