Complete the code to create a curried function that adds two numbers.
add = ->(x, y) { x + y }.[1]
add_two = add.call(2)
result = add_two.call(3)
puts resultThe curry method transforms a lambda into a curried function, allowing partial application of arguments.
Complete the code to partially apply the first argument of the curried function.
multiply = ->(x, y) { x * y }.curry
double = multiply.[1](2)
puts double.call(5)After currying, you can partially apply arguments by calling the function with fewer arguments.
Fix the error in the code to correctly curry the lambda.
adder = lambda { |x, y| x + y }.[1]
puts adder.call(1).call(2)The correct method to curry a lambda is curry. There is no currying or curry! method.
Fill both blanks to create a curried function and partially apply the first argument.
concat = ->(a, b) { a + b }.[1]
hello = concat.[2]('Hello, ')
puts hello.call('World!')First, use curry to enable currying, then use call to partially apply the first argument.
Fill all three blanks to create a curried function, partially apply arguments, and call the final function.
power = ->(base, exponent) { base ** exponent }.[1]
square = power.[2](2)
cube = power.[3](3)
puts square.call(4)
puts cube.call(3)Use curry to enable currying, then call to partially apply the base argument for square and cube.