Higher-Order Function

noun

say it: “HY-er OR-der FUNK-shun” /ˈhaɪər ˈɔrdər ˈfʌŋkʃən/

A function that takes another function as a value, or hands one back.

What is a higher-order function?

A higher-order function takes another function as an argument, or hands one back. sorted() with a key is one you already use.

def apply_discount(prices, rule):
    return [rule(price) for price in prices]

def half_off(price):
    return price / 2

print(apply_discount([20, 50], half_off))  # [10.0, 25.0]

In a sentence

  • “Checkout became a higher-order function when it started taking this week's deal as a function.”

Level: Journeyman · More Python terms at this level

Updated

In other subjects