-
Notifications
You must be signed in to change notification settings - Fork 530
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
Add TypeOf utility #692
Add TypeOf utility #692
Conversation
Could you add a test where the expression performs a type-level computation via an implicit? |
@milessabin The last one is via implicit:
Note the |
Ahh, right. I really meant something a little more sophisticated than that, which justifies using this construct rather than expanding the type by hand. A non-trivial type-level computation would be good here (maybe a
|
Codecov Report
@@ Coverage Diff @@
## master #692 +/- ##
==========================================
+ Coverage 83.39% 83.44% +0.04%
==========================================
Files 65 65
Lines 2590 2591 +1
Branches 91 91
==========================================
+ Hits 2160 2162 +2
+ Misses 430 429 -1
Continue to review full report at Codecov.
|
@milessabin I added a |
One more thing, I think it would be possible to create a compiler plugin, which supports a special type A = T@forExample(expr) which converts to type A = TypeOf.`expr:T`.type |
For example: type T = Any@forExample(Generic[(Int, String, Boolean)].to((1, "foo", true)).zipWithIndex) As a result, |
Interesting. I think you're getting into refined and singleton-ops territory here. |
A test using |
@milessabin I hope it can perform type-level ops like |
Does this work? case class Baz(i: Int, s: String)
implicit val genBaz: TypeOf.`Generic[Baz]` = cachedImplicit
val reprBaz = genBaz.to(Bar(23, "foo"))
typed[Int :: String :: HNil](reprBaz) If it does, could you add it as a test. If it doesn't it'd be good if we could make it work. |
Or should that be, implicit val genBaz: TypeOf.`Generic[Baz]`.type = cachedImplicit |
Anyhow, the point is that this would capture the |
Or, rather, here. |
Of course, |
Great stuff. It's not immediately obvious that that would work, because the interactions with It's great that this works ... it's a really useful addition to the toolbox ... thanks! :-) |
I guess implicit val genBaz: the.`Generic[Baz]`.type = cachedImplicit |
Oh! Interesting ... that hadn't occurred to me ... does it work? |
Works for me |
No description provided.