Skip to content

Instantly share code, notes, and snippets.

@joshuakfarrar
Last active July 5, 2020 20:58
Show Gist options
  • Save joshuakfarrar/60bd8ff9a3ae8743c29337268d03cf89 to your computer and use it in GitHub Desktop.
Save joshuakfarrar/60bd8ff9a3ae8743c29337268d03cf89 to your computer and use it in GitHub Desktop.
// three ways of expressing registration and sending confirmation e-mail in scala
(R.register _)
.andThen(_
.map(C.withConfirmable)
.map(_ >>= { confirmable => OptionT.liftF(C.sendConfirmationInstructions(confirmable)) })
)
.andThen(_ >>= { _ => Ok() })
.apply(form)
// using for-comprehension
val registered = for {
user <- OptionT.liftF(R.register(form))
confirmable <- C.withConfirmable(user)
sent <- OptionT.liftF(C.sendConfirmationInstructions(confirmable))
} yield sent
registered.value >>= { _ => Ok() }
// and bind
val registered2 = OptionT.liftF(R.register(form)) >>=
C.withConfirmable >>=
{ confirmable => OptionT.liftF(C.sendConfirmationInstructions(_)) }
registered2.value >>= { _ => Ok() }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment