Sha256: 1b270a09e4708f65a0ef148d83ab707770537d92d992203bcdfac51d36b5b82f
Contents?: true
Size: 690 Bytes
Versions: 2
Compression:
Stored size: 690 Bytes
Contents
module Streamer module Functors # Group groups a list by a property and a function class Group < Functor def call group end 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 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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
streamer-0.2.1 | lib/streamer/functors/group.rb |
streamer-0.2.0 | lib/streamer/functors/group.rb |