A Type Driven Approach to Functional Design

来源:互联网 发布:淘宝5星好评 编辑:程序博客网 时间:2024/06/05 08:28
# :: [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 }.flattenend# :: [Event] -> Floatdef 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_fend# :: [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

原创粉丝点击