Skip to content

Instantly share code, notes, and snippets.

@gabro gabro/cats.scala
Created Feb 25, 2017

Embed
What would you like to do?
Monad Transformers for the working programmer
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
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
You can’t perform that action at this time.