Skip to content

Instantly share code, notes, and snippets.

@bijancn
Created May 29, 2018 15:17
Show Gist options
  • Save bijancn/b2551034a6458e928ca9e9a1744ade50 to your computer and use it in GitHub Desktop.
Save bijancn/b2551034a6458e928ca9e9a1744ade50 to your computer and use it in GitHub Desktop.
def buyCoffees(creditCard: CreditCard, n: Int): (List[Coffee], Charge) = {
val purchases = (1 to n).map(i => buyCoffee(creditCard, i))
val (coffees, charges) = purchases.unzip
val reducedCharge = charges.reduce((c1, c2) =>
Charge(c1.creditCard, c1.amount + c2.amount))
(coffees, reducedCharge)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment