Ruby transproc 的可读性更好么?

chenge · 2015年04月18日 · 最后由 luikore 回复于 2015年04月18日 · 1367 次阅读

code 1 的可读性是否好于 code 2? 我感觉是的。 原英文博客

#code 1: function pipeline
require 'transproc/hash'
fn = Transproc(:symbolize_keys) >> Transproc(:rename_keys, user_name: :name)
fn.call({ 'user_name' => 'Jane' })
# => { :name => 'Jane' }

#code 2: OO
hash = { 'user_name' => 'Jane' }
hash.symbolize_keys.tap { |h| h[:name] = h.delete(:user_name) }
# => { :name => 'Jane' }

为什么 Haskell 有 do-notation? 就是为了不像 code 1 那么写代码而像 code 2 那么写,本末倒置了...

#2 楼 @luikore do-notation 好像没什么中文资料,是何方神仙?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号