calculate

an anonymous user · May 04, 2021 · Python
def add1(num):
    return num + 1

def multiply3(num):
    return num * 3

def add5(num):
    return num + 5

def calculate(fns):
    def composed(num):
        val = num
        
        for fn in fns:
            val = fn(val)
        
        return val
    return composed
        
print(calculate([add1, multiply3, add5])(1))

Comments

Please sign up or log in to contribute to the discussion.