First-class functions: Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: Skip Method#to_proc, because Method#[] works as well as Proc#[]. Shorten input lines, never exceed 80 characters for input lines (but an output line is 81 characters).) |
m (→{{header|Ruby}}: Line 9 is now line 6.) |
||
Line 1,141: | Line 1,141: | ||
irb(main):005:0> invlist = [Math.method(:asin), Math.method(:acos), croot] |
irb(main):005:0> invlist = [Math.method(:asin), Math.method(:acos), croot] |
||
=> [#<Method: Math.asin>, #<Method: Math.acos>, #<Proc:0x00000201f6a6c8@(irb):2>] |
=> [#<Method: Math.asin>, #<Method: Math.acos>, #<Proc:0x00000201f6a6c8@(irb):2>] |
||
irb(main): |
irb(main):006:0> funclist.zip(invlist).map {|f, invf| compose[invf, f][0.5]} |
||
=> [0.5, 0.4999999999999999, 0.5]</lang> |
=> [0.5, 0.4999999999999999, 0.5]</lang> |
||