mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #2849 from cremno/proc-curry-should-preserve-lambdas
Proc#curry should preserve lambdas
This commit is contained in:
@@ -13,9 +13,11 @@ class Proc
|
||||
end
|
||||
|
||||
def curry(arity=self.arity)
|
||||
type = :proc
|
||||
abs = lambda {|a| a < 0 ? -a - 1 : a}
|
||||
arity = abs[arity]
|
||||
if lambda?
|
||||
type = :lambda
|
||||
self_arity = self.arity
|
||||
if (self_arity >= 0 && arity != self_arity) ||
|
||||
(self_arity < 0 && abs[self_arity] > arity)
|
||||
@@ -25,7 +27,7 @@ class Proc
|
||||
|
||||
pproc = self
|
||||
make_curry = proc do |given_args=[]|
|
||||
proc do |*args|
|
||||
send(type) do |*args|
|
||||
new_args = given_args + args
|
||||
if new_args.size >= arity
|
||||
pproc[*new_args]
|
||||
|
||||
@@ -41,6 +41,9 @@ assert('Proc#curry') do
|
||||
assert_raise(ArgumentError) { b.curry[1, 2][3, 4] }
|
||||
assert_raise(ArgumentError) { b.curry(5) }
|
||||
assert_raise(ArgumentError) { b.curry(1) }
|
||||
|
||||
assert_false(proc{}.curry.lambda?)
|
||||
assert_true(lambda{}.curry.lambda?)
|
||||
end
|
||||
|
||||
assert('Proc#parameters') do
|
||||
|
||||
Reference in New Issue
Block a user