Created
May 29, 2018 15:17
-
-
Save bijancn/b2551034a6458e928ca9e9a1744ade50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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