Created
February 25, 2017 10:52
-
-
Save gabro/792ed58a35bb01da4ccea07f64ff69d6 to your computer and use it in GitHub Desktop.
Monad Transformers for the working programmer
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
import cats.data.OptionT, cats.std.future._ | |
def findAddressByUserId(id: Long): Future[Option[Address]] = | |
(for { | |
user <- OptionT(findUserById(id)) | |
address <- OptionT(findAddressByUser(user)) | |
} yield address).value |
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
def findUserById(id: Long): OptionT[Future, User] = | |
OptionT { ??? } | |
def findAddressByUser(user: User): OptionT[Future, Address] = | |
OptionT { ??? } | |
def findAddressByUserId(id: Long): OptionT[Future, Address]] = | |
for { | |
user <- findUserById(id)) | |
address <- findAddressByUser(user)) | |
} yield address |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment