Skip to content

Instantly share code, notes, and snippets.

@Tvaroh
Created September 25, 2018 16:21
Show Gist options
  • Save Tvaroh/207ba3b287e12d33b113df1a0583eab8 to your computer and use it in GitHub Desktop.
Save Tvaroh/207ba3b287e12d33b113df1a0583eab8 to your computer and use it in GitHub Desktop.

Revisions

  1. Tvaroh created this gist Sep 25, 2018.
    21 changes: 21 additions & 0 deletions ExecuteUnsafe.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    import scala.concurrent.Future

    /** Typeclass for interoperating with legacy code which uses Scala futures. */
    trait ExecuteUnsafe[F[_]] {

    def unsafeToFuture[T](mt: F[T]): Future[T]

    }

    object ExecuteUnsafe {

    def apply[F[_]: ExecuteUnsafe]: ExecuteUnsafe[F] =
    implicitly[ExecuteUnsafe[F]]

    implicit val future: ExecuteUnsafe[Future] = FutureExecuteUnsafe

    private object FutureExecuteUnsafe extends ExecuteUnsafe[Future] {
    override def unsafeToFuture[T](future: Future[T]): Future[T] = future
    }

    }