Skip to content

Commit

Permalink
Derive capture from cats-effect Sync instead of IO
Browse files Browse the repository at this point in the history
  • Loading branch information
BenFradet committed Jul 8, 2018
1 parent 6283421 commit 2c7ac98
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import github4s.{HttpRequestBuilder, HttpRequestBuilderExtension, HttpRequestBui
import github4s.GithubResponses.GHResponse
import io.circe.Decoder

import scala.concurrent.Future

trait IOHttpRequestBuilderExtensionJS extends HttpRequestBuilderExtensionJS {

import monix.execution.Scheduler.Implicits.global
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package github4s.cats.effect.js
import cats.effect.IO
import fr.hmil.roshttp.response.SimpleHttpResponse
import github4s.HttpRequestBuilderExtensionJS
import github4s.cats.effect.{IOCaptureInstance, IOHttpRequestBuilderExtensionJS}
import github4s.cats.effect.{IOHttpRequestBuilderExtensionJS, SyncCaptureInstance}
import github4s.free.interpreters.Interpreters
import github4s.implicits._

trait ImplicitsJS extends IOHttpRequestBuilderExtensionJS with IOCaptureInstance {
trait ImplicitsJS extends IOHttpRequestBuilderExtensionJS with SyncCaptureInstance {
implicit val intInstanceIORosHttp =
new Interpreters[IO, SimpleHttpResponse]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ class CatsEffectJSSpec extends AsyncFunSuite with Matchers {

// only here for the 80% coverage, to remove once JS makes use of Captures
test("IOCapture == IO.apply") {
ioCaptureInstance.capture("a").unsafeRunSync shouldBe IO("a").unsafeRunSync
syncCaptureInstance[IO].capture("a").unsafeRunSync shouldBe IO("a").unsafeRunSync
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package github4s.cats.effect.jvm

import cats.effect.IO
import cats.effect.Sync
import github4s.HttpRequestBuilderExtensionJVM
import github4s.cats.effect.IOCaptureInstance
import github4s.cats.effect.SyncCaptureInstance
import github4s.free.interpreters.Interpreters
import github4s.implicits._
import scalaj.http.HttpResponse

trait ImplicitsJVM extends HttpRequestBuilderExtensionJVM with IOCaptureInstance {
implicit val intInstanceIOScalaJ =
new Interpreters[IO, HttpResponse[String]]
}
trait ImplicitsJVM extends HttpRequestBuilderExtensionJVM with SyncCaptureInstance {
implicit def intInstanceSyncScalaJ[F[_]: Sync] =
new Interpreters[F, HttpResponse[String]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package github4s.cats.effect

import cats.effect.IO
import cats.effect.Sync
import github4s.free.interpreters.Capture

trait IOCaptureInstance {
implicit val ioCaptureInstance = new Capture[IO] {
override def capture[A](a: A): IO[A] = IO(a)
trait SyncCaptureInstance {
implicit def syncCaptureInstance[F[_]: Sync] = new Capture[F] {
override def capture[A](a: A): F[A] = Sync[F].delay(a)
}
}

0 comments on commit 2c7ac98

Please sign in to comment.