Lab 2 - HOF

Questions: 1, 2, 4, 5 are non-coding.

Instructions: https://inst.eecs.berkeley.edu/~cs61a/su19/lab/lab02/

Solution: https://github.com/tomthestrom/cs61a/blob/master/lab/lab02/lab02.py

Q3: Lambdas and Currying

Write a function lambda_curry2 that will curry any two argument function using lambdas. See the doctest or refer to the textbook if you're not sure what this means.

Your solution to this problem should fit entirely on the return line. You can try writing it first without this restriction, but rewrite it after in one line to test your understanding of this topic.

def lambda_curry2(func):
    """
    Returns a Curried version of a two-argument function FUNC.
    >>> from operator import add
    >>> curried_add = lambda_curry2(add)
    >>> add_three = curried_add(3)
    >>> add_three(5)
    8
    """
    "*** YOUR CODE HERE ***"
    return ______

Q3: Solution

def lambda_curry2(func):
    """
    Returns a Curried version of a two-argument function FUNC.
    >>> from operator import add
    >>> curried_add = lambda_curry2(add)
    >>> add_three = curried_add(3)
    >>> add_three(5)
    8
    """
    "*** YOUR CODE HERE ***"
    return lambda x: lambda y: func(x, y)

Last updated