Created
December 16, 2016 13:33
-
-
Save jonboiser/1c231ec3c37927268e6dbf5c7e95a84b 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
/* @flow */ | |
// daggy.tagged(arguments) | |
//declare module 'daggy' { | |
declare function tagged<T>(...args: string[]): (...xs: Array<T>) => {[k: string]: T}; | |
//} | |
//import daggy from 'daggy'; | |
var Tuple3 = tagged('x', 'y', 'z'); | |
var _123 = Tuple3(1, 2, 3); // optional new keyword | |
_123.x == 1 && _123.y == 2 && _123.z == 3; // true | |
_123 instanceof Tuple3 == true; // true | |
type Caser<T> = (cs: {[k: $Keys<T> | '_']: Function}) => any | |
type Caser2 = (cs: {_: Function}) => any | |
declare function Type<T>(types: T): { case: Caser<T>, [k: $Keys<T>]: Function } | |
const types = Type({ | |
Foo: [], | |
Bar: [], | |
}); | |
types.Foo(); | |
types.Bar(1); | |
// types.Bill(); | |
types.case({ | |
Foo: () => null, | |
Bar: () => 1, | |
_: () => null, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment