Last active
January 23, 2016 16:34
-
-
Save NTCoding/9d6f49b3b3b8dd1674bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class SetExample extends FreeSpec with Matchers { | |
| val userEmail = "abc@mailinator.com" | |
| var sentEmailTo = "NOTSENT" | |
| "When the winner is selected they are immediately notified by email" in { | |
| SelectWinnerOfCompetition(ret(userEmail), set(sentEmailTo = _))() | |
| assert(sentEmailTo === userEmail) | |
| } | |
| def ret[A](a: A): Unit => A = _ => a | |
| // carry out some side effect i.e 'set' a value indicating the side effect occurred | |
| def set[A](f: A => Unit): A => Unit = f(_) | |
| } | |
| object SelectWinnerOfCompetition { | |
| type EmailAddress = String | |
| type SelectWinner = Unit => EmailAddress | |
| type SendWinnerEmail = EmailAddress => Unit | |
| def apply(s: SelectWinner, e: SendWinnerEmail)() = e(s()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment