If we have such two functions...
def findUserById(id: Long): Future[Option[User]] = ???
def findAddressByUser(user: User): Future[Option[Address]] = ???
...then we are able to use cats OptionT
monad transformer to write for-comprehension with them easily:
for {
user <- OptionT(findUserById(id))
address <- OptionT(findAddressByUser(user))
} ...
I'd like to compose future of sequences this way, like this:
def findUsersBySomeField(value: FieldValue): Future[Seq[User]] = ???
def findAddressesByUser(user: User): Future[Seq[Address]] = ???
for {
user <- SeqT(findUsersBySomeField(value))
address <- SeqT(findAddressesByUser(user))
} ...
But I can't find any SeqT
implementation in Cats or Scalaz. Does some implementation of such monad transformer exist or I need to write monad transformer myself? Not that it too hard, just don't want to reinvent the wheel.
(example at the beginning of my question is brought from this article)