I have a strange problem. I created two methods, which return Lists
:
override def createContributorsList(url: String, params: String): F[List[Contributor]] = getContributorsFromClient(url, params).fold[List[Contributor]](_ => List(), res => res)
override def createReposList(organization: String, params: String): F[List[GitRepository]] = getReposFromClient(organization, params).fold[List[GitRepository]](_ => List(), res => res)
Now I want to call these methods (they connect to a Git
repository and get contributors for a given organization):
val res = for {
repos <- stats.createReposList("github", "")
contr = repos.foreach(r => println(stats.createContributorsList(r.contributors_url,"").unsafeRunSync()))
} yield (repos,contr)
res.unsafeRunSync
As you see, I needed to call unsafeRunSync
method twice to retrieve all the data. Why do I need to do it this way? Could it be done in another way? I think I should run unsafeRunSync
only once - when I need to run program, not all the time.