Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ lazy val debugJS = debug.js

lazy val examples = (project in file("examples"))
.settings(name := "fetch-examples")
.dependsOn(fetchJVM)
.dependsOn(fetchJVM, debugJVM)
.settings(noPublishSettings: _*)
.settings(examplesSettings: _*)
.settings(Seq(
Expand Down
46 changes: 32 additions & 14 deletions examples/src/test/scala/GithubExample.scala
Original file line number Diff line number Diff line change
Expand Up @@ -189,28 +189,36 @@ class GithubExample extends WordSpec with Matchers {

case class Project(repo: Repo, contributors: List[Contributor], languages: List[Language])

"We can fetch org repos" in {
def fetchProject[F[_]: ConcurrentEffect](repo: Repo): Fetch[F, Project] =
(repoContributors(repo), repoLanguages(repo)).mapN({
case (contribs, langs) =>
Project(repo = repo, contributors = contribs, languages = langs)
})

def fetch[F[_]: ConcurrentEffect] =
for {
repos <- orgRepos("47deg")
projects <- repos.traverse(fetchProject[F])
} yield projects
def fetchProject[F[_]: ConcurrentEffect](repo: Repo): Fetch[F, Project] =
(repoContributors(repo), repoLanguages(repo)).mapN({
case (contribs, langs) =>
Project(repo = repo, contributors = contribs, languages = langs)
})

val io = Fetch.runLog[IO](fetch)
def fetchOrg[F[_]: ConcurrentEffect](org: String) =
for {
repos <- orgRepos(org)
projects <- repos.traverse(fetchProject[F])
} yield projects

def fetchOrgStars[F[_]: ConcurrentEffect](org: String): Fetch[F, Int] =
fetchOrg(org).map(projects => projects.map(_.repo.stargazers_count).sum)

def fetchOrgContributors[F[_]: ConcurrentEffect](org: String): Fetch[F, Int] =
fetchOrg(org).map(projects => projects.map(_.contributors.toSet).fold(Set())(_ ++ _).size)

def fetchOrgLanguages[F[_]: ConcurrentEffect](org: String): Fetch[F, Int] =
fetchOrg(org).map(projects => projects.map(_.languages.toSet).fold(Set())(_ ++ _).size)

"We can fetch org repos" in {
val io = Fetch.runLog[IO](fetchOrg("47deg"))

val (log, result) = io.unsafeRunSync

log.rounds.size shouldEqual 2
}

"We can fetch multiple repos in parallel" in {

def fetchRepo[F[_]: ConcurrentEffect](r: (String, String)): Fetch[F, Repo] =
Fetch(r, Repos.source)

Expand All @@ -228,6 +236,16 @@ class GithubExample extends WordSpec with Matchers {
log.rounds.size shouldEqual 1
}

"We can combine everything" in {
def fetch[F[_]: ConcurrentEffect](org: String): Fetch[F, (List[Project], Int, Int, Int)] =
(fetchOrg(org), fetchOrgStars(org), fetchOrgContributors(org), fetchOrgLanguages(org)).tupled

val io = Fetch.runLog[IO](fetch("47deg"))
val (log, result) = io.unsafeRunSync

log.rounds.size shouldEqual 2
}

// Github HTTP api

val GITHUB: Uri = Uri.unsafeFromString("https://api.github.com")
Expand Down
Loading