Skip to content

Instantly share code, notes, and snippets.

@luisenriquecorona
Last active March 11, 2020 07:21
Show Gist options
  • Save luisenriquecorona/9fada8b084a4470ec51ca32cb4f653e2 to your computer and use it in GitHub Desktop.
Save luisenriquecorona/9fada8b084a4470ec51ca32cb4f653e2 to your computer and use it in GitHub Desktop.
Is straightforward: promos is a list of functions. Once you get used to the idea that functions are first class objects, it naturally follows that building data structures holding functions often makes sense.
>>> Order(joe, long_order, best_promo)
<Order total: 10.00 due: 9.30>
>>> Order(joe, banana_cart, best_promo)
<Order total: 30.00 due: 28.50>
>>> Order(ann, cart, best_promo)
<Order total: 42.00 due: 39.90>
promos = [fidelity_promo, bulk_item_promo, large_order_promo]
def best_promo(order):
"""Select best discount available
"""
return max(promo(order) for promo in promos)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment