|
| 1 | +declare module TsPatternMatching { |
| 2 | + interface Case<X> { |
| 3 | + (x: X): boolean; |
| 4 | + } |
| 5 | + interface Matched<X, Y> { |
| 6 | + (x: X): Y; |
| 7 | + } |
| 8 | + interface Resolvable<X, Y> { |
| 9 | + resolve(): Y; |
| 10 | + } |
| 11 | + interface Caseable<X, Y> extends Resolvable<X, Y> { |
| 12 | + caseOf(_case: Case<X>, _matched: Matched<X, Y>): Matchable<X, Y>; |
| 13 | + } |
| 14 | + interface Matchable<X, Y> extends Caseable<X, Y> { |
| 15 | + _(_matched: Matched<X, Y>): Default<X, Y>; |
| 16 | + } |
| 17 | + class MatchError extends Error { |
| 18 | + } |
| 19 | + class Subject<X, Y> implements Caseable<X, Y> { |
| 20 | + protected subject: X; |
| 21 | + constructor(subject: X); |
| 22 | + caseOf(_case: Case<X>, _matched: Matched<X, Y>): Match<X, Y>; |
| 23 | + resolve(): Y; |
| 24 | + } |
| 25 | + class Default<X, Y> implements Resolvable<X, Y> { |
| 26 | + protected _subject: X; |
| 27 | + protected _matched: Matched<X, Y>; |
| 28 | + protected _parent: Resolvable<X, Y>; |
| 29 | + constructor(_subject: X, _matched: Matched<X, Y>, _parent: Resolvable<X, Y>); |
| 30 | + resolve(): Y; |
| 31 | + } |
| 32 | + class Match<X, Y> implements Matchable<X, Y> { |
| 33 | + protected _subject: X; |
| 34 | + protected _case: Case<X>; |
| 35 | + protected _matched: Matched<X, Y>; |
| 36 | + protected _parent: Resolvable<X, Y>; |
| 37 | + constructor(_subject: X, _case: Case<X>, _matched: Matched<X, Y>, _parent: Resolvable<X, Y>); |
| 38 | + caseOf(_case: Case<X>, _matched: Matched<X, Y>): Matchable<X, Y>; |
| 39 | + _(_matched: Matched<X, Y>): Default<X, Y>; |
| 40 | + resolve(): Y; |
| 41 | + } |
| 42 | + function match<X, Y>(subject: X): Subject<X, Y>; |
| 43 | +} |
| 44 | +declare var module: { |
| 45 | + exports: any; |
| 46 | + require(id: string): any; |
| 47 | + id: string; |
| 48 | + filename: string; |
| 49 | + loaded: boolean; |
| 50 | + parent: any; |
| 51 | + children: any[]; |
| 52 | +}; |
| 53 | +/** |
| 54 | + * @name tspatternmatching |
| 55 | + * @namespace Hold classes and functions related to TsPatternMatching library. |
| 56 | + */ |
| 57 | +declare module 'tspatternmatching' { |
| 58 | + export = TsPatternMatching; |
| 59 | +} |
0 commit comments