我有一个奇怪的问题。我创建了两个方法,它们返回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)
现在我想调用这些方法(它们连接到Git
存储库并获取给定组织的贡献者):
val res = for {
repos <- stats.createReposList("github", "")
contr = repos.foreach(r => println(stats.createContributorsList(r.contributors_url,"").unsafeRunSync()))
} yield (repos,contr)
res.unsafeRunSync
如您所见,我需要调用unsafeRunSync
方法两次以检索所有数据。为什么我需要这样做?可以用其他方式完成吗?我想我应该只运行一次unsafeRunSync
-当我需要运行程序时,而不是一直运行。