Comments (2)
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.
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)
- NullPointerException on NoContent (204) response HOT 4
- Use cats-effect bracket HOT 5
- Support multipart requests HOT 7
- Add functionality for checking status codes of a response HOT 1
- Make Uri parser more restrictive HOT 4
- Runtime exceptions with Apache HTTP backend HOT 3
- BasicAuth renders wrong header name HOT 1
- Documentation Request: How to consume response and headers in one request. HOT 2
- content type is wrong HOT 1
- Separate API and implementation HOT 7
- Make interptrans not require `F` to be a `Sync` HOT 1
- convert interpreters to methods of objects HOT 1
- WebSocket support HOT 2
- Scala 2.13 support HOT 6
- Hammock.constructHeaders does not format cookies correctly. HOT 2
- x-www-form-urlencoded content-type support HOT 1
- Doesn't load with sbt
- drop scalajs support HOT 2
- readme: "It has good documentation." links to a "404 Page not found"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hammock.