é¢æ°åè¨èªã©ããªäººã¯ãRubyã§ãã«ãªã¼åããããªã£ã¦ããã¨æãã¾ã(ç¹ã«Haskellã©ããªäººã¯ãã®å¾åãå¼·ãããã«æãã¾ã)ãã¨ãããã¨ã§ããããªã¡ã½ãããæ¸ãã¦ã¿ã¾ããã module Kernel def curry(sym, *a1) f = sym.respond_to?(:call) ? sym : method(sym) lambda do |*a2| f.call(*(a1 + a2)) end end end 使ãæ¹ã¯ãããªæãã§ããmapã®ä¾ãè¦ã¦ãã ãããããä½ã¦ç¾ããã®ã§ãããã def add(a, b) a + b end p curry(:add, 2)[3] # => 5 p curry(method(:add), 2)[3] # => 5 p curry(lambda {|a, b| a * b}, 2)[3] # => 6 p (1 .. 10).ma
{{#tags}}- {{label}}
{{/tags}}