Ruby transproc 的可读性更好么?

chenge · April 18, 2015 · Last by luikore replied at April 18, 2015 · 1367 hits

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 好像没什么中文资料,是何方神仙?

You need to Sign in before reply, if you don't have an account, please Sign up first.