Skip to content

Instantly share code, notes, and snippets.

@jliszka
Created June 2, 2012 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jliszka/2860408 to your computer and use it in GitHub Desktop.
Save jliszka/2860408 to your computer and use it in GitHub Desktop.
class !<:<[A, B]
implicit def any[A, B]: A !<:< B = new !<:<[A, B]
implicit def sub1[A, B >: A]: A !<:< B = new !<:<[A, B]
implicit def sub2[A, B >: A]: A !<:< B = new !<:<[A, B]
abstract class Tag
abstract class Unlimited
abstract class Unselected
abstract class Unskipped
class AddTag[TT, T, In, Out]
implicit def addTag1[TT, T <: TT, In]: AddTag[TT, T, In, In with TT] = null
implicit def addTag2[TT, T, In](implicit ev: T !<:< TT): AddTag[TT, T, In, In] = null
class RemoveTag[TT, In, Out]
implicit def removeUnlimited[T, Out1, Out2](implicit a: AddTag[Unselected, T, Tag, Out1],
b: AddTag[Unskipped, T, Out1, Out2]): RemoveTag[Unlimited, T, Out2] = null
implicit def removeUnskipped[T, Out1, Out2](implicit a: AddTag[Unselected, T, Tag, Out1],
b: AddTag[Unlimited, T, Out1, Out2]): RemoveTag[Unskipped, T, Out2] = null
implicit def removeUnselected[T, Out1, Out2](implicit a: AddTag[Unlimited, T, Tag, Out1],
b: AddTag[Unskipped, T, Out1, Out2]): RemoveTag[Unselected, T, Out2] = null
class Query[T] {
def limit[_ >: T <: Unlimited, T2](n: Int)(implicit a: RemoveTag[Unlimited, T, T2]): Query[T2] = this.asInstanceOf[Query[T2]]
def skip[_ >: T <: Unskipped, T2](n: Int)(implicit a: RemoveTag[Unskipped, T, T2]): Query[T2] = this.asInstanceOf[Query[T2]]
def select[_ >: T <: Unselected, T2]()(implicit a: RemoveTag[Unselected, T, T2]): Query[T2] = this.asInstanceOf[Query[T2]]
}
val q = new Query[Tag with Unlimited with Unselected with Unskipped]
q.limit(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment