This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
monapt.d.ts
190 lines (190 loc) · 7.5 KB
/
monapt.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
declare module monapt {
interface Tuple1<A> {
_1: A;
}
var Tuple1: <A>(a: A) => Tuple1<A>;
interface Tuple2<A, B> {
_1: A;
_2: B;
}
var Tuple2: <A, B>(a: A, b: B) => Tuple2<A, B>;
}
declare module monapt {
interface IOptionMatcher<A> {
Some? (value: A): void;
None? (): void;
}
interface Option<A> {
isEmpty: boolean;
get(): A;
getOrElse(defaultValue: () => A): A;
orElse(alternative: () => Option<A>): Option<A>;
match(matcher: IOptionMatcher<A>);
map<B>(f: (value: A) => B): Option<B>;
flatMap<B>(f: (value: A) => Option<B>): Option<B>;
filter(predicate: (value: A) => boolean): Option<A>;
reject(predicate: (value: A) => boolean): Option<A>;
foreach(f: (value: A) => void): void;
}
class Some<A> implements Option<A> {
private value;
public isEmpty: boolean;
constructor(value: A);
public get(): A;
public getOrElse(defaultValue: () => A): A;
public orElse(alternative: () => Option<A>): Option<A>;
public match(matcher: IOptionMatcher<A>): void;
public map<B>(f: (value: A) => B): Option<B>;
public flatMap<B>(f: (value: A) => Option<B>): Option<B>;
public filter(predicate: (value: A) => boolean): Option<A>;
public reject(predicate: (value: A) => boolean): Option<A>;
public foreach(f: (value: A) => void): void;
}
class None<A> implements Option<A> {
public isEmpty: boolean;
public get(): A;
public getOrElse(defaultValue: () => A): A;
public orElse(alternative: () => Option<A>): Option<A>;
public match(matcher: IOptionMatcher<A>): void;
public map<B>(f: (value: A) => B): Option<B>;
public flatMap<B>(f: (value: A) => Option<B>): Option<B>;
public filter(predicate: (value: A) => boolean): Option<A>;
public reject(predicate: (value: A) => boolean): Option<A>;
public foreach(f: (value: A) => void): void;
}
}
declare module monapt {
interface ITryMatcher<T> {
Success? (value: T): void;
Failure? (error: Error): void;
}
interface Try<T> {
isSuccess: boolean;
isFailure: boolean;
get(): T;
getOrElse(defaultValue: () => T): T;
orElse(alternative: () => Try<T>): Try<T>;
match(matcher: ITryMatcher<T>);
map<U>(f: (value: T) => U): Try<U>;
flatMap<U>(f: (value: T) => Try<U>): Try<U>;
filter(predicate: (value: T) => boolean): Try<T>;
reject(predicate: (value: T) => boolean): Try<T>;
foreach(f: (value: T) => void): void;
recover(fn: (error: Error) => T): Try<T>;
recoverWith(fn: (error: Error) => Try<T>): Try<T>;
}
class Success<T> implements Try<T> {
private value;
public isSuccess: boolean;
public isFailure: boolean;
constructor(value: T);
public get(): T;
public getOrElse(defaultValue: () => T): T;
public orElse(alternative: () => Try<T>): Try<T>;
public match(matcher: ITryMatcher<T>): void;
public map<U>(f: (value: T) => U): Try<U>;
public flatMap<U>(f: (value: T) => Try<U>): Try<U>;
public filter(predicate: (value: T) => boolean): Try<T>;
public reject(predicate: (value: T) => boolean): Try<T>;
public foreach(f: (value: T) => void): void;
public recover(fn: (error: Error) => T): Try<T>;
public recoverWith(fn: (error: Error) => Try<T>): Try<T>;
}
class Failure<T> implements Try<T> {
private error;
public isSuccess: boolean;
public isFailure: boolean;
constructor(error: Error);
public get(): T;
public getOrElse(defaultValue: () => T): T;
public orElse(alternative: () => Try<T>): Try<T>;
public match(matcher: ITryMatcher<T>): void;
public map<U>(f: (value: T) => U): Try<U>;
public flatMap<U>(f: (value: T) => Try<U>): Try<U>;
public filter(predicate: (value: T) => boolean): Try<T>;
public reject(predicate: (value: T) => boolean): Try<T>;
public foreach(f: (value: T) => void): void;
public recover(fn: (error: Error) => T): Try<T>;
public recoverWith(fn: (error: Error) => Try<T>): Try<T>;
}
var Try: <T>(f: () => T) => Try<T>;
}
declare module monapt {
interface ICrackerProducer<F> {
(f: F): void;
}
class Cracker<F extends Function> {
private fired;
private callbacks;
private producer;
public fire(producer: ICrackerProducer<F>): void;
private fireAll();
public add(fn: F): void;
}
}
declare module monapt {
interface ICompleteFucntion<T> {
(trier: monapt.Try<T>): void;
}
interface IFutureSuccess<T> {
(value: T): void;
}
interface IFutureFailure<T> {
(error: Error): void;
}
interface IFuturePromiseLike<T> {
(value: T): void;
(error: Error): void;
success: IFutureSuccess<T>;
failure: IFutureFailure<T>;
}
class Future<T> {
private cracker;
constructor(future: (promise: IFuturePromiseLike<T>) => void);
static succeed<T>(value: T): Future<T>;
static failed<T>(error: Error): Future<T>;
public success(value: T): void;
public failure(error: Error): void;
public onComplete(callback: ICompleteFucntion<T>): void;
public onSuccess(callback: (value: T) => void): void;
public onFailure(callback: (error: Error) => void): void;
public map<U>(f: (value: T, promise: IFuturePromiseLike<U>) => void): Future<U>;
public flatMap<U>(f: (value: T) => Future<U>): Future<U>;
public filter(predicate: (value: T) => boolean): Future<T>;
public reject(predicate: (value: T) => boolean): Future<T>;
public recover(fn: (e: Error, promise: IFuturePromiseLike<T>) => void): Future<T>;
public recoverWith(fn: (e: Error) => Future<T>): Future<T>;
}
class Promise<T> extends Future<T> {
public isComplete: boolean;
constructor();
public success(value: T): void;
public failure(error: Error): void;
public future(): Future<T>;
}
var future: <T>(f: (promise: IFuturePromiseLike<T>) => void) => Future<T>;
}
declare module monapt {
interface IHashable {
hash? (): string;
}
class Map<K extends IHashable, V> {
private real;
private selector;
constructor(key: K, value: V, ...keysAndValues: any[]);
constructor(raw: Object);
constructor();
private ensureSelector(hint?);
private add(key, value);
public foreach(f: (key: K, value: V) => void): void;
public map<K2, V2>(f: (key: K, value: V) => monapt.Tuple2<K2, V2>): Map<K2, V2>;
public flatMap<K2, V2>(f: (key: K, value: V) => Map<K2, V2>): Map<K2, V2>;
public mapValues<U>(f: (value: V) => U): Map<K, U>;
public filter(predicate: (key: K, value: V) => boolean): Map<K, V>;
public reject(predicate: (key: K, value: V) => boolean): Map<K, V>;
public find(f: (key: K, value: V) => boolean): monapt.Option<monapt.Tuple2<K, V>>;
public get(key: K): monapt.Option<V>;
public getOrElse(key: K, defaultValue: () => V): V;
public head(): monapt.Option<monapt.Tuple2<K, V>>;
}
}