Last active
October 26, 2017 07:14
-
-
Save Axect/b351726def3ef2ef9a6248bf340e80ab to your computer and use it in GitHub Desktop.
Side Effect Example
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
// Side Effect | |
class Cafe { | |
def buyCoffee(cc: CreditCard): Coffee = { // Method of class is determined with def | |
val cup = new Coffee() | |
cc.charge(cup.price) // Side Effect! | |
cup // Scala doesn't need return | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment