@@ -62,11 +62,12 @@ Implementation of PromiseLike.then() for proper functioning of await
62
62
63
63
** return** * PromiseLike* object which inclose new value
64
64
65
- Monad<T >.prototype.then<TResult1 = T, TResult2 = never>(
66
- onfulfilled?: ( ( value: T ) => TResult1 | PromiseLike<TResult1 > ) | undefined | null,
67
- onrejected?: ( ( reason: any ) => TResult2 | PromiseLike<TResult2 > ) | undefined | null
68
- ): PromiseLike<TResult1 | TResult2>
69
-
65
+ ``` typescript
66
+ Monad < T > .prototype .then < TResult1 = T , TResult2 = never > (
67
+ onfulfilled ?: ( ( value : T ) => TResult1 | PromiseLike < TResult1 > ) | undefined | null ,
68
+ onrejected ?: ( ( reason : any ) => TResult2 | PromiseLike < TResult2 > ) | undefined | null
69
+ ): PromiseLike < TResult1 | TResult2 >
70
+ ```
70
71
It is internally utilized by * bind()* .
71
72
72
73
#### Monad.prototype.get()
@@ -75,63 +76,174 @@ Returns the value inclosed inside container.
75
76
76
77
Signature for * Maybe* is:
77
78
78
- Maybe<T>.prototype.get(): T | undefined
79
+ ``` typescript
80
+ Maybe < T > .prototype .get (): T | undefined
81
+ ```
79
82
80
83
Signature for * Result* is:
81
84
82
- Result<T, E>.prototype.get(): T | E
85
+ ``` typescript
86
+ Result < T , E > .prototype .get (): T | E
87
+ ```
83
88
84
89
#### Monad.prototype.getOrElse()
85
90
86
91
Returns the inclosed primary value or the one provided as an argument.
87
92
88
93
Signature for * Maybe* is:
89
94
90
- Maybe<T>.prototype.getOrElse( value: T): T
95
+ ``` typescript
96
+ Maybe < T > .prototype .getOrElse ( value : T ): T
97
+ ```
91
98
92
99
Signature for * Result* is:
93
100
94
- Result<T, E>.prototype.getOrElse( value: T): T
95
-
96
- ### Maybe< T >
101
+ ``` typescript
102
+ Result < T , E > . prototype . getOrElse ( value : T ): T
103
+ ```
97
104
98
- Maybe< T > itself represents a union type of Just< T > and None< T >.
105
+ ### Maybe
99
106
100
- #### Maybe<T >(value: T | undefined | null) => Maybe <T >
107
+ * Maybe<T >* itself represents a union type of Just< T > and None <T >.
101
108
102
109
It is also a * smart factory* which turns Nullable object to * Just<T >* or * None<T >* accordingly.
103
110
104
- #### Just<T >
111
+ ``` typescript
112
+ Maybe <T >(value : T | undefined | null ) => Maybe < T >
113
+ ```
105
114
106
- Represents a value of specified type.
115
+ #### Just
107
116
108
- #### Just< T >( value: T) => Maybe <T >
117
+ Represents a value of specified type. It can be created via a factory which wraps the value with * Just <T >*
109
118
110
- Wraps a value with * Just<T >*
119
+ ``` typescript
120
+ Just <T >(value : T ) => Maybe < T >
121
+ ```
111
122
112
- #### None< T >
123
+ #### None
113
124
114
- Represents a absents of a value with specified type.
125
+ Represents an absents of a value with specified type. It can be created via a factory with specified type.
115
126
116
- #### None<T >() => Maybe<T >
127
+ ``` typescript
128
+ None <T >() => Maybe < T >
129
+ ```
117
130
118
- Creates None of specified type.
131
+ #### isJust
119
132
120
- #### isJust< T >(obj: any): obj is Just< T >
133
+ It exists as a stand alone function which checks wether object of any type is * Just*
121
134
122
- Checks wether object of any type is * Just*
135
+ ``` typescript
136
+ isJust <T >(obj : any ): obj is Just < T >
137
+ ```
138
+
139
+ Moreover * Maybe* has a method dedicated to the same goal.
140
+
141
+ ``` typescript
142
+ Maybe < T > .prototype .isJust (): obj is Just < T >
143
+ ```
144
+
145
+ #### isNone
146
+
147
+ It exists as a stand alone function which checks wether object of any type is * None*
148
+
149
+ ``` typescript
150
+ isNone <T >(obj : any ): obj is None < T >
151
+ ```
123
152
124
- #### isNone< T >(obj: any): obj is Just< T >
153
+ Moreover * Maybe * has a method dedicated to the same goal.
125
154
126
- Checks wether object of any type is * None*
155
+ ``` typescript
156
+ Maybe < T > .prototype .isNone (): obj is Just < T >
157
+ ```
127
158
159
+ ### Result
128
160
161
+ * Result<T, E>* itself represents a union type of Success<T, E> and Failure<T, E>.
129
162
163
+ It is also a * smart factory* which calls provided function and stores its output as * Success<T, E>* or * Failure<T, E>* accordingly.
130
164
165
+ ``` typescript
166
+ Maybe <T , E extends Throwable >(action : () => T | Result <T , E >) => Result <T , E >
167
+ ` ` `
131
168
169
+ #### Success
170
+
171
+ Represents a value of specified type. It can be created via a factory which wraps the value with *Success<T, E>*
172
+
173
+ ` ` ` typescript
174
+ Success <T , E extends Throwable >(value : T ) => Result <T , E >
175
+ ` ` `
132
176
177
+ #### Failure
178
+
179
+ Represents an error which explains an absents of a value. It can be created via a factory with specified type.
180
+
181
+ ` ` ` typescript
182
+ Failure <T , E extends Throwable >(error : E ) => Result <T , E >
183
+ ` ` `
184
+
185
+ #### isSuccess
186
+
187
+ It exists as a stand alone function which checks wether object of any type is *Success*
188
+
189
+ ` ` ` typescript
190
+ isSuccess <T >(obj : any ): obj is Success <T >
191
+ ` ` `
192
+
193
+ Moreover *Result* has a method dedicated to the same goal.
194
+
195
+ ` ` ` typescript
196
+ Result <T , E >.prototype .isSuccess (): obj is Success <T , E >
197
+ ` ` `
198
+
199
+ #### isFailure
200
+
201
+ It exists as a stand alone function which checks wether object of any type is *Failure*
202
+
203
+ ` ` ` typescript
204
+ isFailure <T , E >(obj : any ): obj is Failure <T , E >
205
+ ` ` `
206
+
207
+ Moreover *Result* has a method dedicated to the same goal.
208
+
209
+ ` ` ` typescript
210
+ Result <T , E >.prototype .isFailure (): obj is Failure <T >
211
+ ` ` `
133
212
134
213
## Contribution guidelines
135
214
215
+ The project is based on *npm* eco-system. Therefore development process is organized via *npm* scripts.
216
+
217
+ For installation of dependencies run
218
+
219
+ npm install
220
+
221
+ Build application once
222
+
223
+ npm run build
224
+
225
+ Build application and watch for changes of files
226
+
227
+ npm run build:w
228
+
229
+ Run tslint one time for CI
230
+
231
+ npm run lint
232
+
233
+ Unit tests in a watching mode are performed by
234
+
235
+ npm run test
236
+
237
+ A single run of test suit
238
+
239
+ npm run test:once
240
+
241
+ A single run of test suit with test coverage report
242
+
243
+ npm run cover
244
+
245
+ A single run of test suit with test coverage report
136
246
247
+ npm run test:ci
137
248
249
+ Everybody is welcome to contribute and submit pull requests. Please communicate your ideas and suggestions via *issues*.
0 commit comments