From 494ae88b82acff2bf35913ce6a0d3fc113ab5ebc Mon Sep 17 00:00:00 2001 From: Ryan Peters Date: Thu, 14 Jan 2021 08:36:56 -0600 Subject: [PATCH] Fix compiler warnings across project --- fetch-debug/src/main/scala/document.scala | 4 ++-- .../src/test/scala/GithubExample.scala | 18 ++++++++++-------- fetch/src/main/scala/fetch.scala | 13 ++++++++----- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/fetch-debug/src/main/scala/document.scala b/fetch-debug/src/main/scala/document.scala index b3893476..432aeae8 100644 --- a/fetch-debug/src/main/scala/document.scala +++ b/fetch-debug/src/main/scala/document.scala @@ -42,7 +42,7 @@ abstract class Document { * Format this document on `writer` and try to set line * breaks so that the result fits in `width` columns. */ - def format(width: Int, writer: Writer) { + def format(width: Int, writer: Writer): Unit = { type FmtState = (Int, Boolean, Document) def fits(w: Int, state: List[FmtState]): Boolean = @@ -67,7 +67,7 @@ abstract class Document { fits(w, (i, false, d) :: z) } - def spaces(n: Int) { + def spaces(n: Int): Unit = { var rem = n while (rem >= 16) { writer write " "; rem -= 16 } if (rem >= 8) { writer write " "; rem -= 8 } diff --git a/fetch-examples/src/test/scala/GithubExample.scala b/fetch-examples/src/test/scala/GithubExample.scala index 9a1ad90d..6f980c8a 100644 --- a/fetch-examples/src/test/scala/GithubExample.scala +++ b/fetch-examples/src/test/scala/GithubExample.scala @@ -85,12 +85,14 @@ class GithubExample extends AnyWordSpec with Matchers { val url = GITHUB / "repos" / owner / repo +? ("access_token", ACCESS_TOKEN) val req = Request[F](Method.GET, url) for { - result <- c.fetch[Repo](req)({ - case Status.Ok(res) => - res.as[Repo] - case res => - CF.raiseError(new Exception(res.body.toString)) - }) + result <- c + .run(req) + .use[F, Repo] { + case Status.Ok(res) => + res.as[Repo] + case res => + CF.raiseError(new Exception(res.body.toString)) + } } yield Option(result) } } @@ -228,7 +230,7 @@ class GithubExample extends AnyWordSpec with Matchers { val GITHUB: Uri = Uri.unsafeFromString("https://api.github.com") private def fetchCollectionRecursively[F[_], A](c: Client[F], req: Request[F])(implicit - CF: MonadError[F, Throwable], + CF: BracketThrow[F], E: EntityDecoder[F, List[A]] ): F[List[A]] = { val REL_NEXT = "rel=\"next\"".r @@ -256,7 +258,7 @@ class GithubExample extends AnyWordSpec with Matchers { ) for { - result <- c.fetch[List[A]](req) { + result <- c.run(req).use[F, List[A]] { case Status.Ok(res) => if (hasNext(res)) { for { diff --git a/fetch/src/main/scala/fetch.scala b/fetch/src/main/scala/fetch.scala index 5c52710a..cee83484 100644 --- a/fetch/src/main/scala/fetch.scala +++ b/fetch/src/main/scala/fetch.scala @@ -166,7 +166,8 @@ object `package` { val newRequest = Batch(combined, ds) val newResult = CombinationSuspend((r: FetchStatus) => r match { - case FetchDone(m: Map[Any, Any]) => + case FetchDone(preM) => + val m = preM.asInstanceOf[Map[Any, Any]] val xResult = m.get(aId).map(FetchDone(_)).getOrElse(FetchMissing()) val yResult = m.get(anotherId).map(FetchDone(_)).getOrElse(FetchMissing()) CombinationBarrier(() => x.result, xResult) @@ -184,7 +185,8 @@ object `package` { val newRequest = Batch(combined, ds) val newResult = CombinationSuspend((r: FetchStatus) => r match { - case FetchDone(m: Map[Any, Any]) => + case FetchDone(preM) => + val m = preM.asInstanceOf[Map[Any, Any]] val oneResult = m.get(oneId).map(FetchDone(_)).getOrElse(FetchMissing()) CombinationBarrier(() => x.result, oneResult) .flatMap(() => y.result) @@ -201,7 +203,8 @@ object `package` { val newRequest = Batch(combined, ds) val newResult = CombinationSuspend((r: FetchStatus) => r match { - case FetchDone(m: Map[Any, Any]) => + case FetchDone(preM) => + val m = preM.asInstanceOf[Map[Any, Any]] val oneResult = m.get(oneId).map(FetchDone(_)).getOrElse(FetchMissing()) CombinationBarrier(() => y.result, oneResult) .flatMap(() => x.result) @@ -258,8 +261,8 @@ object `package` { // Fetch Monad - implicit def fetchM[F[_]: Monad]: Monad[Fetch[F, ?]] = - new Monad[Fetch[F, ?]] with StackSafeMonad[Fetch[F, ?]] { + implicit def fetchM[F[_]: Monad]: Monad[Fetch[F, *]] = + new Monad[Fetch[F, *]] with StackSafeMonad[Fetch[F, *]] { def pure[A](a: A): Fetch[F, A] = Unfetch( Monad[F].pure(Done(a))