Guest User

Untitled

a guest
Mar 22nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import cats.effect.IO
  2. import scala.concurrent.{Await, Future}
  3. import scala.concurrent.duration._
  4. import scala.concurrent.ExecutionContext.Implicits.global
  5.  
  6. case class Repository()
  7. case class MetaData(name: String)
  8.  
  9. trait APIClient {
  10. def getRepositories: IO[List[Repository]]
  11.  
  12. def getMetadata(r: Repository): IO[MetaData]
  13. }
  14.  
  15. def allMetaData(client: APIClient): IO[List[IO[MetaData]]] =
  16. client.getRepositories.map(
  17. _.map(
  18. repository =>
  19. client.getMetadata(repository)
  20. )
  21. )
  22.  
  23. // Naive implementation for demostration purposes
  24. def printMetaDataOrderedByName(allMetaData: IO[List[IO[MetaData]]]): Unit =
  25. Await.result(
  26. Future.sequence(
  27. allMetaData.unsafeRunSync().map(_.unsafeToFuture())
  28. ),
  29. 1.minute
  30. ).sortWith(_.name < _.name)
  31. .foreach(println)
Add Comment
Please, Sign In to add comment