Coder Social home page Coder Social logo

Comments (2)

rlecomte avatar rlecomte commented on May 27, 2024 1

I'm not sure to understand the whole picture but here is my 2 cents :

/*
  Keep interpreter signature as simple as possible. Just a F type without any behavior.
 */
trait InterpTrans[F[_]] {
  def trans: HttpF ~> F
}
/*
 Just an alias for Kleisli interpreter
*/
trait KleisliInterTrans[F[_], Client] extends InterpTrans[Kleisli[F, Client, ?]]
/*
 Here is the trick : deal with legacy by using client in context to execute kleisli interpreter
*/
trait LegacyTrans[F, Client] extends InterpTrans[F[_]] {
  val client: Client
  val kleisliTrans: KleisliInterTrans[F, Client, ?]

  def trans: HttpF ~> F = kleisliTrans.transK andThen λ[Kleisli[F, Client, ?] ~> F](_.run(client))

  def transK: HttpF ~> Kleisli[F, Client, ?] = kleisliTrans.trans
}
/*
An implementation for apache http client
*/
case class ApacheHttpClientTrans[F[_]](client: HttpClient) extends LegacyTrans[F, HttpClient] {
  val kleisliTrans = ApacheHttpClientKleisliTrans
}

object ApacheHttpClientKleisliTrans extends KleisliInterTrans[F, HttpClient] {
   //implementation
}

In this way, we don't introduce any breaking change and keep InterpTrans as simple as possible. This allow to implement any interpreter we want.

from hammock.

pepegar avatar pepegar commented on May 27, 2024

Hi @rlecomte!

Yeah, you're right that receiving it as a constructor param and using
it in the transK method is a bit repetitive.

However, since the interface we need to follow is the one from
InterpTrans,
we need it in both places, as for now, since the transK method is
being used in other projects.

I've however thought of changing the InterpTrans more than
once, that meaning that since for all implementations of the
interpreter we'd need a value of the target's http client (apache's
HttpClient, Akka's HttpExt...), I'd delete the trans
method from the typeclass and only use the transK method.

trait InterpTrans[F[_], Client] {
  def transK(implicit S: Sync[F]): HttpF ~> Kleisli[F, Client, ?]
}

And we'd create instances of the like this:

implicit object AkkaInterpreter extends InterpTrans[F, HttpExt] {
  def transK...
}

What do you think about it? if we end up creating interpreters like
so, we'd end up not needing the constructor parameter.

from hammock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.