Skip to content

Instantly share code, notes, and snippets.

@wheaties
Last active July 31, 2018 20:55
Show Gist options
  • Save wheaties/17322f3f13e224fd79f3 to your computer and use it in GitHub Desktop.
Save wheaties/17322f3f13e224fd79f3 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