Recall & Review
beginner
What is currying in Ruby?
Currying is a technique where a method with multiple arguments is transformed into a series of methods each taking one argument. It allows you to call a method step-by-step with one argument at a time.
Click to reveal answer
beginner
What does partial application mean?
Partial application means fixing some arguments of a function and creating a new function that takes the remaining arguments. It helps reuse functions with some preset values.
Click to reveal answer
intermediate
How do you create a curried function in Ruby?
You can create a curried function by calling
curry on a Proc or lambda. For example: add = ->(a, b) { a + b }.curry creates a curried version of the add function.Click to reveal answer
intermediate
What is the difference between currying and partial application?
Currying transforms a function to take one argument at a time, returning new functions until all arguments are given. Partial application fixes some arguments and returns a function for the rest. Partial application is a special case of currying.
Click to reveal answer
beginner
Example: How to partially apply a function in Ruby using currying?
Given
multiply = ->(a, b) { a * b }.curry, you can fix the first argument like double = multiply.call(2). Now double.call(5) returns 10.Click to reveal answer
What does the
curry method do in Ruby?✗ Incorrect
The
curry method changes a function so it takes one argument at a time, returning new functions until all arguments are provided.What is partial application useful for?
✗ Incorrect
Partial application lets you fix some arguments, creating a new function that needs fewer arguments.
Which Ruby object can be curried?
✗ Incorrect
Only Proc or lambda objects can be curried using the
curry method.What will
add = ->(a, b) { a + b }.curry; add.call(2).call(3) return?✗ Incorrect
Currying allows calling the function one argument at a time. Here, 2 + 3 equals 5.
Partial application is a special case of which concept?
✗ Incorrect
Partial application fixes some arguments, and currying transforms functions to take one argument at a time. Partial application is considered a special case of currying.
Explain in your own words what currying is and how it works in Ruby.
Think about how a function with many arguments can be called step-by-step.
You got /3 concepts.
Describe partial application and how it differs from currying with an example in Ruby.
Focus on fixing some arguments vs. taking one argument at a time.
You got /3 concepts.