# :: [Event] -> [Month, Int]
def avg_lines_per_commit_by_month events
cls_by_month = lines_added_per_commit(events).group_by { |date,_| month_from_date$
cls_by_month.map { |_,cls| cls.map { |cl| cl[1] }.mean }.flatten
end
# :: [Event] -> Float
def percent_reduction method_events
non_deleted = method_events.select { |e| e.status != :deleted }
return 0.0 if non_deleted.count == 0
num_reductions = non_deleted.each_cons(2) \
.map { |before,after| after.method_length < before.me$
.count(true)
num_reductions / non_deleted.count.to_f
end
# :: [Event] -> [FixNum]
def refactoring_reduction_profile events
events.group_by(&:method_name) \
.map { |_,e| percent_reduction(e) } \
.freq_by { |e| (e * 100/10).to_i }
end
It's about thinking about the shape of data first before thinking about the names in some TDD.
http://infoq.com/presentations/Type-Functional-Design