Skip to content

Instantly share code, notes, and snippets.

@NTCoding
Last active January 23, 2016 16:34
Show Gist options
  • Select an option

  • Save NTCoding/9d6f49b3b3b8dd1674bc to your computer and use it in GitHub Desktop.

Select an option

Save NTCoding/9d6f49b3b3b8dd1674bc to your computer and use it in GitHub Desktop.
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