module DR::CoreExt::Proc
Public Instance Methods
call_block(*args,**opts)
click to toggle source
Safely call our block, even if the user passed in something of a different arity (lambda case)
# File lib/dr/ruby_ext/core_modules.rb, line 241 def call_block(*args,**opts) if arity >= 0 case arity when 0 call(**opts) else call(args[0...arity],**opts) end else call(*args,**opts) end end
compose(g)
click to toggle source
return self o g f.compose(g).(5,6)
# File lib/dr/ruby_ext/core_modules.rb, line 265 def compose(g) lambda do |*a,&b| self.call(*g.call(*a,&b)) end end
rcurry(*args,&b)
click to toggle source
similar to curry, but pass the provided arguments on the right (a difference to Proc#curry is that we pass the argument directly, not via .call)
# File lib/dr/ruby_ext/core_modules.rb, line 257 def rcurry(*args,&b) return ::Proc.new do |*a,&b| self.call(*a,*args,&b) end end
uncurry()
click to toggle source
(->(x) {->(y) {x+y}}).uncurry.(2,3) #=> 5 (->(x,y) {x+y}).curry.uncurry.(2,3) #=>5
# File lib/dr/ruby_ext/core_modules.rb, line 273 def uncurry lambda do |*a| a.reduce(self) {|fun,v| fun.call(v)} end end