Skip to content

Instantly share code, notes, and snippets.

@DevAndArtist
Last active Jul 1, 2016
Embed
What would you like to do?
// we generate the boundary with `A | B` or directly OneOf<A, B>
enum OneOf<...T> {
...case $#(T)
// Bikeshedding variadic enum casses:
// we might need an index to set the value?
init(index: Int, value: T) {
self = .$index(value)
}
}
/// Usage:
/// A | B | C == OneOf<A, B, C>
func |<T, U>(_: T.Type, _: U.Type) -> OneOf<T, U>.Type {
// I also use the proposal to remove `.self` magic here
return OneOf<T, U>
}
// Here is how to merge OneOf into a single dimension
func |<...T, U>(_: OneOf<...T>.Type, _: U.Type) -> OneOf<...T, U>.Type {
// Copy and merge types into the new `OneOf` type
return OneOf<...T, U>
}
func |<T, ...U>(_: T.Type, _: OneOf<...U>.Type) -> OneOf<T, ...U>.Type {
// Copy and merge types into the new `OneOf` type
return OneOf<T, ...U>
}
func |<...T, ...U>(_: OneOf<...T>.Type, _: OneOf<...U>.Type) -> OneOf<...T, ...U>.Type {
// Copy and merge types into the new `OneOf` type
return OneOf<...T, ...U>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment