Sha256: 6b18535efbbcf42a34e1783d27b5609f61f746e093ce38bf4d8838dd53398a85

Contents?: true

Size: 831 Bytes

Versions: 24

Compression:

Stored size: 831 Bytes

Contents

class Proc
  
  def curry
    case self.arity
    when 2 then curry2
    when 3 then curry3
    when 4 then curry4
    when 5 then curry5
    else raise "Can't curry more than 5 arguments"
    end
  end
  
  def curry2
    lambda{|a|
      lambda{|b| self.call(a,b)}}
  end
  
  def curry3
    lambda{|a|
      lambda{|b| 
        lambda{|c| self.call(a,b,c)}}}
  end
  
  def curry4
    lambda{|a|
      lambda{|b|
        lambda{|c| 
          lambda{|d| self.call(a,b,c,d)}}}}
  end
  
  def curry5
    lambda{|a|
      lambda{|b|
        lambda{|c|
          lambda{|d|
            lambda{|e| self.call(a,b,c,d,e)}}}}}
  end
  
end

class Object
  def define_singleton_method(name, &block)
    singleton = class << self; self end
    singleton.send(:define_method, name) do |*args|
      block.call(*args)
    end
  end
end
  

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
funkr-0.0.40 lib/funkr/compat/1.8.rb
funkr-0.0.30 lib/funkr/compat/1.8.rb
funkr-0.0.28 lib/funkr/compat/1.8.rb
funkr-0.0.27 lib/funkr/compat/1.8.rb
funkr-0.0.26 lib/funkr/compat/1.8.rb
funkr-0.0.25 lib/funkr/compat/1.8.rb
funkr-0.0.24 lib/funkr/compat/1.8.rb
funkr-0.0.23 lib/funkr/compat/1.8.rb
funkr-0.0.22 lib/funkr/compat/1.8.rb
funkr-0.0.21 lib/funkr/compat/1.8.rb
funkr-0.0.20 lib/funkr/compat/1.8.rb
funkr-0.0.19 lib/funkr/compat/1.8.rb
funkr-0.0.18 lib/funkr/compat/1.8.rb
funkr-0.0.17 lib/funkr/compat/1.8.rb
funkr-0.0.16 lib/funkr/compat/1.8.rb
funkr-0.0.15 lib/funkr/compat/1.8.rb
funkr-0.0.14 lib/funkr/compat/1.8.rb
funkr-0.0.12 lib/funkr/compat/1.8.rb
funkr-0.0.11 lib/funkr/compat/1.8.rb
funkr-0.0.10 lib/funkr/compat/1.8.rb