diff --git a/elastic4s-client-akka/src/test/scala/com/sksamuel/elastic4s/akka/AkkaHttpClientTest.scala b/elastic4s-client-akka/src/test/scala/com/sksamuel/elastic4s/akka/AkkaHttpClientTest.scala index 10ca24f44a..56bff89cc8 100644 --- a/elastic4s-client-akka/src/test/scala/com/sksamuel/elastic4s/akka/AkkaHttpClientTest.scala +++ b/elastic4s-client-akka/src/test/scala/com/sksamuel/elastic4s/akka/AkkaHttpClientTest.scala @@ -108,11 +108,9 @@ class AkkaHttpClientTest extends AnyFlatSpec with Matchers with DockerTests with } it should "propagate headers if included" in { - implicit val executor: Executor[Future] = new Executor[Future] { - override def exec(client: HttpClient[Future], request: ElasticRequest): Future[HttpResponse] = { - val cred = Base64.getEncoder.encodeToString("user123:pass123".getBytes(StandardCharsets.UTF_8)) - Executor.FutureExecutor.exec(client, request.copy(headers = Map("Authorization" -> s"Basic $cred"))) - } + implicit val executor: Executor[Future] = (client: HttpClient[Future], request: ElasticRequest) => { + val cred = Base64.getEncoder.encodeToString("user123:pass123".getBytes(StandardCharsets.UTF_8)) + client.send(request.copy(headers = Map("Authorization" -> s"Basic $cred"))) } mkAkkaBasedClient.execute { diff --git a/elastic4s-client-pekko/src/test/scala/com/sksamuel/elastic4s/pekko/PekkoHttpClientTest.scala b/elastic4s-client-pekko/src/test/scala/com/sksamuel/elastic4s/pekko/PekkoHttpClientTest.scala index 89a5855a82..4c0fe71bf0 100644 --- a/elastic4s-client-pekko/src/test/scala/com/sksamuel/elastic4s/pekko/PekkoHttpClientTest.scala +++ b/elastic4s-client-pekko/src/test/scala/com/sksamuel/elastic4s/pekko/PekkoHttpClientTest.scala @@ -109,11 +109,9 @@ class PekkoHttpClientTest extends AnyFlatSpec with Matchers with DockerTests wit } it should "propagate headers if included" in { - implicit val executor: Executor[Future] = new Executor[Future] { - override def exec(client: HttpClient[Future], request: ElasticRequest): Future[HttpResponse] = { - val cred = Base64.getEncoder.encodeToString("user123:pass123".getBytes(StandardCharsets.UTF_8)) - Executor.FutureExecutor.exec(client, request.copy(headers = Map("Authorization" -> s"Basic $cred"))) - } + implicit val executor: Executor[Future] = (client: HttpClient[Future], request: ElasticRequest) => { + val cred = Base64.getEncoder.encodeToString("user123:pass123".getBytes(StandardCharsets.UTF_8)) + client.send(request.copy(headers = Map("Authorization" -> s"Basic $cred"))) } mkPekkoBasedClient.execute { diff --git a/elastic4s-client-sttp/src/test/scala/com/sksamuel/elastic4s/sttp/SttpRequestHttpClientTest.scala b/elastic4s-client-sttp/src/test/scala/com/sksamuel/elastic4s/sttp/SttpRequestHttpClientTest.scala index 664da05f29..e66ee36679 100644 --- a/elastic4s-client-sttp/src/test/scala/com/sksamuel/elastic4s/sttp/SttpRequestHttpClientTest.scala +++ b/elastic4s-client-sttp/src/test/scala/com/sksamuel/elastic4s/sttp/SttpRequestHttpClientTest.scala @@ -11,11 +11,9 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future class SttpRequestHttpClientTest extends AnyFlatSpec with Matchers with DockerTests { - implicit val executor: Executor[Future] = new Executor[Future] { - override def exec(client: HttpClient[Future], request: ElasticRequest): Future[HttpResponse] = { - val cred = Base64.getEncoder.encodeToString("user123:pass123".getBytes(StandardCharsets.UTF_8)) - Executor.FutureExecutor.exec(client, request.copy(headers = Map("Authorization" -> s"Basic $cred"))) - } + implicit val executor: Executor[Future] = (client: HttpClient[Future], request: ElasticRequest) => { + val cred = Base64.getEncoder.encodeToString("user123:pass123".getBytes(StandardCharsets.UTF_8)) + client.send(request.copy(headers = Map("Authorization" -> s"Basic $cred"))) } private lazy val sttpClient = SttpRequestHttpClient(ElasticNodeEndpoint("http", elasticHost, elasticPort.toInt, None)) override lazy val client = ElasticClient(sttpClient) diff --git a/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/Executor.scala b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/Executor.scala index 083c86377e..23c5a1f397 100644 --- a/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/Executor.scala +++ b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/Executor.scala @@ -1,6 +1,5 @@ package com.sksamuel.elastic4s -import scala.concurrent.{ExecutionContext, Future} import scala.language.higherKinds trait Executor[F[_]] { @@ -8,13 +7,8 @@ trait Executor[F[_]] { } object Executor { + def apply[F[_]](implicit ev: Executor[F]): Executor[F] = ev - def apply[F[_]: Executor]: Executor[F] = implicitly[Executor[F]] - - implicit def FutureExecutor(implicit ec: ExecutionContext = ExecutionContext.Implicits.global): Executor[Future] = - new Executor[Future] { - override def exec(client: HttpClient[Future], request: ElasticRequest): Future[HttpResponse] = { - client.send(request) - } - } + implicit def defaultExecutor[F[_]]: Executor[F] = + (client: HttpClient[F], request: ElasticRequest) => client.send(request) } diff --git a/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/Functor.scala b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/Functor.scala index 60b2c254dc..abdafa068c 100644 --- a/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/Functor.scala +++ b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/Functor.scala @@ -9,7 +9,7 @@ trait Functor[F[_]] { object Functor { - def apply[F[_]: Functor]: Functor[F] = implicitly[Functor[F]] + def apply[F[_]](implicit f: Functor[F]): Functor[F] = f implicit def FutureFunctor(implicit ec: ExecutionContext = ExecutionContext.Implicits.global): Functor[Future] = new Functor[Future] { diff --git a/elastic4s-effect-cats-2/src/main/scala/com/sksamuel/elastic4s/cats/effect/CatsEffectExecutor.scala b/elastic4s-effect-cats-2/src/main/scala/com/sksamuel/elastic4s/cats/effect/CatsEffectExecutor.scala deleted file mode 100644 index 3b857d559c..0000000000 --- a/elastic4s-effect-cats-2/src/main/scala/com/sksamuel/elastic4s/cats/effect/CatsEffectExecutor.scala +++ /dev/null @@ -1,14 +0,0 @@ -package com.sksamuel.elastic4s.cats.effect - -import cats.effect.{Async, IO} -import com.sksamuel.elastic4s.{ElasticRequest, Executor, HttpClient, HttpResponse} - -import scala.language.higherKinds - -class CatsEffectExecutor[F[_]] extends Executor[F] { - override def exec(client: HttpClient[F], request: ElasticRequest): F[HttpResponse] = - client.send(request) -} - -@deprecated("Use CatsEffectExecutor[IO] instead") -class IOExecutor extends CatsEffectExecutor[IO] diff --git a/elastic4s-effect-cats-2/src/main/scala/com/sksamuel/elastic4s/cats/effect/instances/CatsEffectInstances.scala b/elastic4s-effect-cats-2/src/main/scala/com/sksamuel/elastic4s/cats/effect/instances/CatsEffectInstances.scala index 67125cc634..6232730b99 100644 --- a/elastic4s-effect-cats-2/src/main/scala/com/sksamuel/elastic4s/cats/effect/instances/CatsEffectInstances.scala +++ b/elastic4s-effect-cats-2/src/main/scala/com/sksamuel/elastic4s/cats/effect/instances/CatsEffectInstances.scala @@ -1,20 +1,14 @@ package com.sksamuel.elastic4s.cats.effect.instances -import cats.effect.{Async, IO} import cats.{Functor => CatsFunctor} -import com.sksamuel.elastic4s.cats.effect.CatsEffectExecutor -import com.sksamuel.elastic4s.{Executor, Functor} +import com.sksamuel.elastic4s.Functor + +import scala.language.higherKinds trait CatsEffectInstances { implicit def catsFunctor[F[_]: CatsFunctor]: Functor[F] = new Functor[F] { override def map[A, B](fa: F[A])(f: A => B): F[B] = CatsFunctor[F].map(fa)(f) } - - implicit def catsEffectExecutor[F[_]: Async]: Executor[F] = - new CatsEffectExecutor[F] - - //this needs to be at the bottom - implicit val ioExecutor: Executor[IO] = new CatsEffectExecutor[IO] } @deprecated("Use CatsEffectInstances instead") diff --git a/elastic4s-effect-cats/src/main/scala/com/sksamuel/elastic4s/cats/effect/CatsEffectExecutor.scala b/elastic4s-effect-cats/src/main/scala/com/sksamuel/elastic4s/cats/effect/CatsEffectExecutor.scala deleted file mode 100644 index 9be01e88ed..0000000000 --- a/elastic4s-effect-cats/src/main/scala/com/sksamuel/elastic4s/cats/effect/CatsEffectExecutor.scala +++ /dev/null @@ -1,14 +0,0 @@ -package com.sksamuel.elastic4s.cats.effect - -import cats.effect.IO -import com.sksamuel.elastic4s.{ElasticRequest, Executor, HttpClient, HttpResponse} - -import scala.language.higherKinds - -class CatsEffectExecutor[F[_]] extends Executor[F] { - override def exec(client: HttpClient[F], request: ElasticRequest): F[HttpResponse] = - client.send(request) -} - -@deprecated("Use CatsEffectExecutor[IO] instead") -class IOExecutor extends CatsEffectExecutor[IO] diff --git a/elastic4s-effect-cats/src/main/scala/com/sksamuel/elastic4s/cats/effect/instances/CatsEffectInstances.scala b/elastic4s-effect-cats/src/main/scala/com/sksamuel/elastic4s/cats/effect/instances/CatsEffectInstances.scala index 67125cc634..6232730b99 100644 --- a/elastic4s-effect-cats/src/main/scala/com/sksamuel/elastic4s/cats/effect/instances/CatsEffectInstances.scala +++ b/elastic4s-effect-cats/src/main/scala/com/sksamuel/elastic4s/cats/effect/instances/CatsEffectInstances.scala @@ -1,20 +1,14 @@ package com.sksamuel.elastic4s.cats.effect.instances -import cats.effect.{Async, IO} import cats.{Functor => CatsFunctor} -import com.sksamuel.elastic4s.cats.effect.CatsEffectExecutor -import com.sksamuel.elastic4s.{Executor, Functor} +import com.sksamuel.elastic4s.Functor + +import scala.language.higherKinds trait CatsEffectInstances { implicit def catsFunctor[F[_]: CatsFunctor]: Functor[F] = new Functor[F] { override def map[A, B](fa: F[A])(f: A => B): F[B] = CatsFunctor[F].map(fa)(f) } - - implicit def catsEffectExecutor[F[_]: Async]: Executor[F] = - new CatsEffectExecutor[F] - - //this needs to be at the bottom - implicit val ioExecutor: Executor[IO] = new CatsEffectExecutor[IO] } @deprecated("Use CatsEffectInstances instead") diff --git a/elastic4s-effect-monix/src/main/scala/com/sksamuel/elastic4s/monix/TaskExecutor.scala b/elastic4s-effect-monix/src/main/scala/com/sksamuel/elastic4s/monix/TaskExecutor.scala deleted file mode 100644 index 1e91b9972b..0000000000 --- a/elastic4s-effect-monix/src/main/scala/com/sksamuel/elastic4s/monix/TaskExecutor.scala +++ /dev/null @@ -1,9 +0,0 @@ -package com.sksamuel.elastic4s.monix - -import com.sksamuel.elastic4s.{ElasticRequest, Executor, HttpClient, HttpResponse} -import monix.eval.Task - -class TaskExecutor extends Executor[Task] { - override def exec(client: HttpClient[Task], request: ElasticRequest): Task[HttpResponse] = - client.send(request) -} diff --git a/elastic4s-effect-monix/src/main/scala/com/sksamuel/elastic4s/monix/instances/TaskInstances.scala b/elastic4s-effect-monix/src/main/scala/com/sksamuel/elastic4s/monix/instances/TaskInstances.scala index 57b184d7bc..8161c820a1 100644 --- a/elastic4s-effect-monix/src/main/scala/com/sksamuel/elastic4s/monix/instances/TaskInstances.scala +++ b/elastic4s-effect-monix/src/main/scala/com/sksamuel/elastic4s/monix/instances/TaskInstances.scala @@ -1,13 +1,10 @@ package com.sksamuel.elastic4s.monix.instances import com.sksamuel.elastic4s.Functor -import com.sksamuel.elastic4s.monix.TaskExecutor import monix.eval.Task trait TaskInstances { implicit val taskFunctor: Functor[Task] = new Functor[Task] { override def map[A, B](fa: Task[A])(f: A => B): Task[B] = fa.map(f) } - - implicit val taskExecutor: TaskExecutor = new TaskExecutor } diff --git a/elastic4s-effect-scalaz/src/main/scala/com/sksamuel/elastic4s/scalaz/TaskExecutor.scala b/elastic4s-effect-scalaz/src/main/scala/com/sksamuel/elastic4s/scalaz/TaskExecutor.scala deleted file mode 100644 index 3b4d1b07f4..0000000000 --- a/elastic4s-effect-scalaz/src/main/scala/com/sksamuel/elastic4s/scalaz/TaskExecutor.scala +++ /dev/null @@ -1,9 +0,0 @@ -package com.sksamuel.elastic4s.scalaz - -import com.sksamuel.elastic4s.{ElasticRequest, Executor, HttpClient, HttpResponse} -import scalaz.concurrent.Task - -class TaskExecutor extends Executor[Task] { - override def exec(client: HttpClient[Task], request: ElasticRequest): Task[HttpResponse] = - client.send(request) -} diff --git a/elastic4s-effect-scalaz/src/main/scala/com/sksamuel/elastic4s/scalaz/instances/TaskInstances.scala b/elastic4s-effect-scalaz/src/main/scala/com/sksamuel/elastic4s/scalaz/instances/TaskInstances.scala index f4026fc89c..acd3706789 100644 --- a/elastic4s-effect-scalaz/src/main/scala/com/sksamuel/elastic4s/scalaz/instances/TaskInstances.scala +++ b/elastic4s-effect-scalaz/src/main/scala/com/sksamuel/elastic4s/scalaz/instances/TaskInstances.scala @@ -1,13 +1,10 @@ package com.sksamuel.elastic4s.scalaz.instances import com.sksamuel.elastic4s.Functor -import com.sksamuel.elastic4s.scalaz.TaskExecutor import scalaz.concurrent.Task trait TaskInstances { implicit val taskFunctor: Functor[Task] = new Functor[Task] { override def map[A, B](fa: Task[A])(f: A => B): Task[B] = fa.map(f) } - - implicit val taskExecutor: TaskExecutor = new TaskExecutor } diff --git a/elastic4s-effect-zio/src/main/scala/com/sksamuel/elastic4s/zio/instances/TaskInstances.scala b/elastic4s-effect-zio/src/main/scala/com/sksamuel/elastic4s/zio/instances/TaskInstances.scala index 806e8192f8..be9931b3d3 100644 --- a/elastic4s-effect-zio/src/main/scala/com/sksamuel/elastic4s/zio/instances/TaskInstances.scala +++ b/elastic4s-effect-zio/src/main/scala/com/sksamuel/elastic4s/zio/instances/TaskInstances.scala @@ -7,9 +7,4 @@ trait TaskInstances { implicit val taskFunctor: Functor[Task] = new Functor[Task] { override def map[A, B](fa: Task[A])(f: A => B): Task[B] = fa.map(f) } - - implicit val taskExecutor: Executor[Task] = new Executor[Task] { - override def exec(client: HttpClient[Task], request: ElasticRequest): Task[HttpResponse] = - client.send(request) - } } diff --git a/elastic4s-streams-akka/src/main/scala/com/sksamuel/elastic4s/akka/streams/BatchElasticSink.scala b/elastic4s-streams-akka/src/main/scala/com/sksamuel/elastic4s/akka/streams/BatchElasticSink.scala index a374b7f46e..fed3e9425e 100644 --- a/elastic4s-streams-akka/src/main/scala/com/sksamuel/elastic4s/akka/streams/BatchElasticSink.scala +++ b/elastic4s-streams-akka/src/main/scala/com/sksamuel/elastic4s/akka/streams/BatchElasticSink.scala @@ -20,8 +20,6 @@ class BatchElasticSink[T](client: ElasticClient[Future], settings: SinkSettings) override val shape: SinkShape[Seq[T]] = SinkShape.of(in) private implicit val bulkHandler: BulkHandlers.BulkHandler.type = BulkHandlers.BulkHandler - private implicit val executor: Executor[Future] = Executor.FutureExecutor - private implicit val functor: Functor[Future] = Functor.FutureFunctor override def createLogic(inheritedAttributes: Attributes): GraphStageLogic = new GraphStageLogic(shape) { diff --git a/elastic4s-streams-akka/src/main/scala/com/sksamuel/elastic4s/akka/streams/ElasticSource.scala b/elastic4s-streams-akka/src/main/scala/com/sksamuel/elastic4s/akka/streams/ElasticSource.scala index 6cd18dabc2..29a01a6fea 100644 --- a/elastic4s-streams-akka/src/main/scala/com/sksamuel/elastic4s/akka/streams/ElasticSource.scala +++ b/elastic4s-streams-akka/src/main/scala/com/sksamuel/elastic4s/akka/streams/ElasticSource.scala @@ -28,8 +28,6 @@ class ElasticSource(client: ElasticClient[Future], settings: SourceSettings) private implicit val searchHandler: Handler[SearchRequest, SearchResponse] = SearchHandlers.SearchHandler private implicit val scrollHandler: Handler[SearchScrollRequest, SearchResponse] = SearchScrollHandlers.SearchScrollHandler private implicit val clearScrollHandler: Handler[ClearScrollRequest, ClearScrollResponse] = SearchScrollHandlers.ClearScrollHandler - private implicit val executor: Executor[Future] = Executor.FutureExecutor - private implicit val functor: Functor[Future] = Functor.FutureFunctor override def createLogic(inheritedAttributes: Attributes): GraphStageLogic = new GraphStageLogic(shape) with OutHandler { diff --git a/elastic4s-streams-pekko/src/main/scala/com/sksamuel/elastic4s/pekko/streams/BatchElasticSink.scala b/elastic4s-streams-pekko/src/main/scala/com/sksamuel/elastic4s/pekko/streams/BatchElasticSink.scala index 7590b8c283..366fb8cfa1 100644 --- a/elastic4s-streams-pekko/src/main/scala/com/sksamuel/elastic4s/pekko/streams/BatchElasticSink.scala +++ b/elastic4s-streams-pekko/src/main/scala/com/sksamuel/elastic4s/pekko/streams/BatchElasticSink.scala @@ -21,8 +21,6 @@ class BatchElasticSink[T](client: ElasticClient[Future], settings: SinkSettings) override val shape: SinkShape[Seq[T]] = SinkShape.of(in) private implicit val bulkHandler: BulkHandlers.BulkHandler.type = BulkHandlers.BulkHandler - private implicit val executor: Executor[Future] = Executor.FutureExecutor - private implicit val functor: Functor[Future] = Functor.FutureFunctor override def createLogic(inheritedAttributes: Attributes): GraphStageLogic = new GraphStageLogic(shape) { diff --git a/elastic4s-streams-pekko/src/main/scala/com/sksamuel/elastic4s/pekko/streams/ElasticSource.scala b/elastic4s-streams-pekko/src/main/scala/com/sksamuel/elastic4s/pekko/streams/ElasticSource.scala index 2c76545fe3..f036c8c34e 100644 --- a/elastic4s-streams-pekko/src/main/scala/com/sksamuel/elastic4s/pekko/streams/ElasticSource.scala +++ b/elastic4s-streams-pekko/src/main/scala/com/sksamuel/elastic4s/pekko/streams/ElasticSource.scala @@ -28,8 +28,6 @@ class ElasticSource(client: ElasticClient[Future], settings: SourceSettings) private implicit val searchHandler: Handler[SearchRequest, SearchResponse] = SearchHandlers.SearchHandler private implicit val scrollHandler: Handler[SearchScrollRequest, SearchResponse] = SearchScrollHandlers.SearchScrollHandler private implicit val clearScrollHandler: Handler[ClearScrollRequest, ClearScrollResponse] = SearchScrollHandlers.ClearScrollHandler - private implicit val executor: Executor[Future] = Executor.FutureExecutor - private implicit val functor: Functor[Future] = Functor.FutureFunctor override def createLogic(inheritedAttributes: Attributes): GraphStageLogic = new GraphStageLogic(shape) with OutHandler { diff --git a/elastic4s-testkit/src/main/scala/com/sksamuel/elastic4s/testkit/SearchMatchers.scala b/elastic4s-testkit/src/main/scala/com/sksamuel/elastic4s/testkit/SearchMatchers.scala index 9d52b772d3..36d1b7aa17 100644 --- a/elastic4s-testkit/src/main/scala/com/sksamuel/elastic4s/testkit/SearchMatchers.scala +++ b/elastic4s-testkit/src/main/scala/com/sksamuel/elastic4s/testkit/SearchMatchers.scala @@ -7,7 +7,6 @@ import org.scalatest.matchers.{MatchResult, Matcher} import scala.concurrent.Future import scala.concurrent.duration._ -import scala.language.higherKinds trait SearchMatchers extends Matchers { diff --git a/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/http/ElasticClientTests.scala b/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/http/ElasticClientTests.scala index 32d0cc5780..359f1c90de 100644 --- a/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/http/ElasticClientTests.scala +++ b/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/http/ElasticClientTests.scala @@ -25,11 +25,9 @@ class ElasticClientTests extends AnyFlatSpec with Matchers with DockerTests { } it should "propagate headers if included" in { - implicit val executor: Executor[Future] = new Executor[Future] { - override def exec(client: HttpClient[Future], request: ElasticRequest): Future[HttpResponse] = { - val cred = Base64.getEncoder.encodeToString("user123:pass123".getBytes(StandardCharsets.UTF_8)) - Executor.FutureExecutor.exec(client, request.copy(headers = Map("Authorization" -> s"Basic $cred"))) - } + implicit val executor: Executor[Future] = (client: HttpClient[Future], request: ElasticRequest) => { + val cred = Base64.getEncoder.encodeToString("user123:pass123".getBytes(StandardCharsets.UTF_8)) + client.send(request.copy(headers = Map("Authorization" -> s"Basic $cred"))) } mkJavaBasedClient.execute {