$30 off During Our Annual Pro Sale. View Details »

#okark02 lambda_driver

#okark02 lambda_driver

Yuuki Sumida

July 06, 2013
Tweet

More Decks by Yuuki Sumida

Other Decks in Programming

Transcript

  1. Feature • Proc/lambda/Symbol/Method extensions • Symbol extensions • Class extensions

    • UnboundMethod extensions • Object extensions • 全部は紹介できないのでちょっとだけ…
  2. Feature • 関数合成 f = lambda{|x| x.to_s * 2 }

    g = lambda{|y| y.length } h = f.compose g # => #<Proc:0x007ff78aa2ab2> h.(:hoge) # => "44" ( == f.call(g.call(:hoge)) ) f << g # => f.compose(g) f << g < :hoge # => "44" ( == f.call(g.call(:hoge)) ) f >> g # => g.compose(f) f >> g < :hoge # => "8" ( == g.call(f.call(:hoge)) )
  3. Feature • 引数の入れ替え(Proc#flip) f = lambda{|x, y, z| [x, y,

    z]} h = f.flip # => #<Proc:0x007ff78a942fa> h.call(:a).call(:b).call(:c) # => [:b, :a, :c] (== f.curry.call(:b).call(:a).call(:b)) h < :a < :b < :c # => [:b, :a, :c] (== f.curry.call(:b).call(:a).call(:b))
  4. Feature • Object#revapply f = lambda{|x| x * 2 }

    "foo".revapply(f) # => "fooffoo" (== f.call("foo") )