There's an asynchronous client that returns Futures of Lists. To iterate over results I need to use nested map
and flatMap
. Is there a way to create a monad transformer to be able to use simpler for-comprehensions, so it would look something along the lines of
class MetaClient {
def getDatabases: Future[Seq[String]] = ???
def getTables(database: String): Future[Seq[String]] = ???
def getMeta(database: String, table: String): Future[Meta] = ???
}
object GetMeta {
val client = new MetaClient()
val metas = for {
db <- FutureS(client.getDatabases)
table <- FutureS(client.getTables(db))
meta <- FutureS(client.getMeta(db, table))
} yield meta
val result: Seq[Future[Meta]] = metas.run()
}