Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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