SHARE
TWEET

Untitled

a guest Jul 21st, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package util
  2.  
  3. import util.DepTrait.{WithEvidence, WithoutEvidence}
  4. import shapeless.tag
  5. import shapeless.tag.@@
  6.  
  7. object DepTrait {
  8.   trait WithEvidence
  9.   trait WithoutEvidence
  10. }
  11.  
  12. object TestImplicits extends App {
  13.  
  14.   trait Dep {
  15.     def t = "Test"
  16.   }
  17.  
  18.   implicit val e = "Test"
  19.  
  20.   implicit def De(implicit a: String) = tag[WithEvidence][Dep](new Dep {override def t: String = a})
  21.  
  22.   implicit val Dep = tag[WithoutEvidence][Dep](new Dep {})
  23.  
  24.   class TestDependencyUser {
  25.  
  26.     def a(implicit a: Dep @@ WithEvidence) = {
  27.       a.t
  28.     }
  29.  
  30.     def b(implicit a: Dep @@ WithoutEvidence) = {
  31.       a.t
  32.     }
  33.  
  34.   }
  35.  
  36.   val test = new TestDependencyUser
  37.  
  38.   val s = test.a
  39.   val d = test.b
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top