Skip to content

Instantly share code, notes, and snippets.

@frabbit
Created March 20, 2013 12:03
Show Gist options
  • Save frabbit/5204144 to your computer and use it in GitHub Desktop.
Save frabbit/5204144 to your computer and use it in GitHub Desktop.
abstract Choice<A,B>(Dynamic) {
inline function new (x:Dynamic) this = x;
@:from static inline function fromA <A,B>(x:A):Choice<A,B> return new Choice(x);
@:from static inline function fromB <A,B>(x:B):Choice<A,B> return new Choice(x);
}
class Test {
public static function expectStringOrInt (x:Choice<String, Int>) {
}
public static function main () {
expectStringOrInt(1); //works
expectStringOrInt("hi"); //works
expectStringOrInt({ a : "hi"}); //error
expectStringOrInt(1.1); // error
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment