Skip to content

Commit

Permalink
Fix curry_spec
Browse files Browse the repository at this point in the history
This effectively ran the following code:

    @proc_add = Proc.new {|x,y,z| (x||0) + (y||0) + (z||0) }
    tmp = @proc_add.curry(1)[1,2]
    tmp.curry(3)[3,4,5,6].should == 6

The optional argument to `Proc#curry` is the arity of the curried proc.
In other words: if the curried proc gets called with at least 1
argument, which means the value of `tmp` in this example will be equal
to `@proc_add[1,2]`, the result is an Integer and not a new proc object.

The example with a lambda would raise the error in the `curry(1)[1,2]`
part, so the second test was pretty much the same as the first test.
  • Loading branch information
herwinw committed Jul 4, 2024
1 parent 417b7c9 commit 82f972c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions core/proc/curry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,14 @@
end

it "can be passed more than _arity_ arguments if created from a proc" do
-> {
@proc_add.curry(3)[1,2,3,4].should == 6
}.should_not raise_error(ArgumentError)
-> {
@proc_add.curry(1)[1,2].curry(3)[3,4,5,6].should == 6
}.should_not raise_error(ArgumentError)
@proc_add.curry(3)[1,2,3,4].should == 6

@proc_add.curry(3)[1,2].curry(3)[3,4,5,6].should == 6
end

it "raises an ArgumentError if passed more than _arity_ arguments when created from a lambda" do
-> { @lambda_add.curry(3)[1,2,3,4] }.should raise_error(ArgumentError)
-> { @lambda_add.curry(1)[1,2].curry(3)[3,4,5,6] }.should raise_error(ArgumentError)
-> { @lambda_add.curry(3)[1,2].curry(3)[3,4,5,6] }.should raise_error(ArgumentError)
end

it "returns Procs with arities of -1 regardless of the value of _arity_" do
Expand Down

0 comments on commit 82f972c

Please sign in to comment.