Last active
July 5, 2020 20:58
-
-
Save joshuakfarrar/60bd8ff9a3ae8743c29337268d03cf89 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
// 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