Skip to content

Instantly share code, notes, and snippets.

@fedesilva
Forked from wheaties/OneOf.scala
Created July 31, 2018 20:55
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 fedesilva/36e39e21f2b63309efb48ae7560f14db to your computer and use it in GitHub Desktop.
Save fedesilva/36e39e21f2b63309efb48ae7560f14db to your computer and use it in GitHub Desktop.
Type Level OneOf
trait OneOf[Obj, Items]
object OneOf extends LowPriorityOneOf{
implicit def apply[Obj, Items](implicit oneOf: OneOf[Obj, Items]) = oneOf
implicit def left[L, R, Obj <: L] = new OneOf[Obj, L | R]{}
}
protected trait LowPriorityOneOf extends LowPriorityOneOf1{
implicit def right[L, R, Obj <: R] = new OneOf[Obj, L | R]{}
}
protected trait LowPriorityOneOf1{
implicit def recur[L, R, Obj](implicit oneOf: OneOf[Obj, R]) = new OneOf[Obj, L | R]{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment