Challenge - 5 Problems
Curried Ruby Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of curried function with partial application
What is the output of this Ruby code using currying and partial application?
Ruby
def multiply(a, b, c) a * b * c end curried_multiply = method(:multiply).curry partial = curried_multiply.call(2) result = partial.call(3).call(4) puts result
Attempts:
2 left
💡 Hint
Remember that currying transforms a method into a chain of functions each taking one argument.
✗ Incorrect
The method multiply takes three arguments. Currying it allows calling it one argument at a time. Calling with 2 returns a function expecting the next argument, then 3, then 4. The final call computes 2 * 3 * 4 = 24.
❓ Predict Output
intermediate2:00remaining
Result of partial application with Proc
What will this Ruby code print when using partial application with a Proc?
Ruby
adder = ->(x, y, z) { x + y + z }
curried_adder = adder.curry
add_five = curried_adder.call(5)
result = add_five.call(10).call(15)
puts resultAttempts:
2 left
💡 Hint
Currying a Proc works similarly to currying a method.
✗ Incorrect
The lambda takes three arguments and sums them. Currying allows calling with one argument at a time. Calling with 5, then 10, then 15 sums to 30.
🔧 Debug
advanced2:00remaining
Identify the error in currying usage
What error does this Ruby code raise when trying to curry a method incorrectly?
Ruby
def concat(a, b) a + b end curried = method(:concat).curry result = curried.call('Hello').call puts result
Attempts:
2 left
💡 Hint
Check how many arguments the curried function expects at each call.
✗ Incorrect
The curried method expects one argument per call. The second call is made without arguments, causing ArgumentError for wrong number of arguments.
🧠 Conceptual
advanced2:00remaining
Understanding partial application with default arguments
Given this Ruby method with default arguments, what is the output of the curried calls below?
Ruby
def greet(greeting, name = 'friend') "#{greeting}, #{name}!" end curried_greet = method(:greet).curry say_hello = curried_greet.call('Hello') puts say_hello.call
Attempts:
2 left
💡 Hint
Currying does not automatically apply default arguments in Ruby methods.
✗ Incorrect
Currying expects all arguments to be provided one by one. The default argument is ignored in this context, so calling say_hello.call without argument raises ArgumentError.
🚀 Application
expert3:00remaining
Create a curried function for filtering and transforming
You want to create a curried Ruby function that filters an array of numbers by a minimum value and then multiplies the filtered numbers by a factor. Which option correctly defines and uses this curried function to get [20, 30, 40, 60] from [5, 10, 15, 20, 30] with min 10 and factor 2?
Attempts:
2 left
💡 Hint
Remember the order of arguments matters for currying and that map with conditional returns nil for false conditions.
✗ Incorrect
Option A correctly orders arguments as min, factor, arr and uses select to filter before mapping. Option A uses map with conditional which produces nils for filtered out elements. Options B and C have wrong argument order for intended usage.