Last active
July 1, 2016 13:09
-
-
Save DevAndArtist/9a41b90711b33c6bdd2d0a2944d0a68a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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