Guest User

Untitled

a guest
Oct 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. class !<:<[A, B]
  2. implicit def any[A, B]: A !<:< B = new !<:<[A, B]
  3. implicit def sub1[A, B >: A]: A !<:< B = new !<:<[A, B]
  4. implicit def sub2[A, B >: A]: A !<:< B = new !<:<[A, B]
  5.  
  6. abstract class Tag
  7. abstract class Unlimited
  8. abstract class Unselected
  9. abstract class Unskipped
  10.  
  11. class AddTag[TT, T, In, Out]
  12.  
  13. implicit def addTag1[TT, T <: TT, In]: AddTag[TT, T, In, In with TT] = null
  14. implicit def addTag2[TT, T, In](implicit ev: T !<:< TT): AddTag[TT, T, In, In] = null
  15.  
  16. class RemoveTag[TT, In, Out]
  17.  
  18. implicit def removeUnlimited[T, Out1, Out2](implicit a: AddTag[Unselected, T, Tag, Out1],
  19. b: AddTag[Unskipped, T, Out1, Out2]): RemoveTag[Unlimited, T, Out2] = null
  20. implicit def removeUnskipped[T, Out1, Out2](implicit a: AddTag[Unselected, T, Tag, Out1],
  21. b: AddTag[Unlimited, T, Out1, Out2]): RemoveTag[Unskipped, T, Out2] = null
  22. implicit def removeUnselected[T, Out1, Out2](implicit a: AddTag[Unlimited, T, Tag, Out1],
  23. b: AddTag[Unskipped, T, Out1, Out2]): RemoveTag[Unselected, T, Out2] = null
  24.  
  25. class Query[T] {
  26. def limit[_ >: T <: Unlimited, T2](n: Int)(implicit a: RemoveTag[Unlimited, T, T2]): Query[T2] = this.asInstanceOf[Query[T2]]
  27. def skip[_ >: T <: Unskipped, T2](n: Int)(implicit a: RemoveTag[Unskipped, T, T2]): Query[T2] = this.asInstanceOf[Query[T2]]
  28. def select[_ >: T <: Unselected, T2]()(implicit a: RemoveTag[Unselected, T, T2]): Query[T2] = this.asInstanceOf[Query[T2]]
  29. }
  30.  
  31. val q = new Query[Tag with Unlimited with Unselected with Unskipped]
  32. q.limit(3)
Add Comment
Please, Sign In to add comment