New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HList based tupler #60
Comments
@julienrf Do you think it pays the cost of introducing first dependency to core algebra? Idea looks interesting and for sure worth investigating but I'm not sure if its beneficial enough. Mapping to case classes may be a really nice feature though. I had a different idea at some point, to remove tupler at all. User then has to deal with |
In the beginning I considered using shapeless’ Note that it should still be possible to map to case classes without introducing shapeless in the core, but at the (cheap) cost of an additional implicit parameter. |
One advantage of using tuples is that the syntax to “call” an endpoint is very similar to calling a method with several parameters (excepted that it’s a single tuple parameter): val foo: Endpoint[(Int, String), Int] = …
foo((42, "bar")) On the other hand, if we use val foo: Endpoint[Int :: String :: HNil, Int] = …
foo(42 :: "bar" :: HNil) Which is less nice imho. We could support passing a tuple as parameter as well, by having an |
I think we should wait for Scala 3 to implement this feature. In Scala 3, tuples can be used like Shapeless’ HLists. |
Scala 3 tuples will indeed be nice. However, I'm not sure what the migration plan might be here, since the behaviour of Scala 3 As such, perhaps it makes sense to add an trait MyEndpoints extends endpoints4s.algebra.Endpoints {
def tooManyArgs: Endpoint[(Int, Int, Int, Int, Int, Int), Unit] = endpoint(
request = post(
url = path / "foo" / segment[Int]("i1") / segment[Int]("i2") / segment[Int]("i3"),
entity = emptyRequest.xmap(_ => (0,1,2))(_ => ())
),
response = ok(emptyResponse)
)
} ... instead of failing with the type error
|
I guess you mean “on Scala 2 via Shapeless and on Scala 3 via native tuples”. Did you make some experiments to check that the user experience would be good on Scala 2? |
Yes, that’s what I meant. I haven’t yet check the user experience - I want to first see if there was already another plan in place before investigating.
I suspect the user experience wouldn’t be too different: all that would change is the method by which the tupler implicit is resolved (so the only error message users should see is the same implicit not found one they would see before).
When I have some time, I’ll try to implement both the Scala 2 and Scala 3 parts of this.
…Sent from my iPhone
On Aug 15, 2020, at 16:17, Julien Richard-Foy ***@***.***> wrote:
it would just mean that the following would work on 2.12 via Shapeless and on 2.13 via native tuples.
I guess you mean “on Scala 2 via Shapeless and on Scala 3 via native tuples”. Did you make some experiments to check that the user experience would be good on Scala 2?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I've used shapeless' hlist's to build up product types as seen here: https://github.com/Fristi/endpoints-proto/blob/master/algebra/src/main/scala/itinere/Tupler.scala.
Advantages:
Generic
machinery of shapeless to map to case classesThe text was updated successfully, but these errors were encountered: