class Streamer::Functors::Group

Group groups a list by a property and a function

Public Instance Methods

accumulate(list, group_key, operand_key, operator) click to toggle source
# File lib/streamer/functors/group.rb, line 16
def accumulate(list, group_key, operand_key, operator)
  list.each_with_object({}) do |item, val|
    val[item[group_key]] =
      (val[item[group_key]] || 0.0).send(
        operator,
        (item[operand_key].to_f || 0)
      )
  end
end
call() click to toggle source
# File lib/streamer/functors/group.rb, line 5
def call
  group
end
group() click to toggle source
# File lib/streamer/functors/group.rb, line 9
def group
  group_key = options.fetch(:by)
  operand_key = options.fetch(:operand)
  operator = options.fetch(:operator).to_sym
  accumulate(list, group_key, operand_key, operator)
end