0
0
Rubyprogramming~5 mins

Curry and partial application in Ruby - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ADeletes a function
BTransforms a multi-argument function into a chain of single-argument functions
CConverts a function to a string
DRuns a function multiple times
What is partial application useful for?
AMaking a function run faster
BDeleting arguments from a function
CChanging the function's name
DFixing some arguments of a function to reuse it easily
Which Ruby object can be curried?
AProc or lambda
BInteger
CString
DArray
What will add = ->(a, b) { a + b }.curry; add.call(2).call(3) return?
Anil
B23
C5
DError
Partial application is a special case of which concept?
ACurrying
BRecursion
CInheritance
DPolymorphism
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.