Skip to content

Commit 6e47d49

Browse files
authored
Merge pull request #4
Improve documentation and typings
2 parents 8c83a8e + 25fce11 commit 6e47d49

File tree

2 files changed

+138
-26
lines changed

2 files changed

+138
-26
lines changed

README.md

Lines changed: 137 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ Implementation of PromiseLike.then() for proper functioning of await
6262

6363
**return** *PromiseLike* object which inclose new value
6464

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+
```
7071
It is internally utilized by *bind()*.
7172

7273
#### Monad.prototype.get()
@@ -75,63 +76,174 @@ Returns the value inclosed inside container.
7576

7677
Signature for *Maybe* is:
7778

78-
Maybe<T>.prototype.get(): T | undefined
79+
```typescript
80+
Maybe<T>.prototype.get(): T | undefined
81+
```
7982

8083
Signature for *Result* is:
8184

82-
Result<T, E>.prototype.get(): T | E
85+
```typescript
86+
Result<T, E>.prototype.get(): T | E
87+
```
8388

8489
#### Monad.prototype.getOrElse()
8590

8691
Returns the inclosed primary value or the one provided as an argument.
8792

8893
Signature for *Maybe* is:
8994

90-
Maybe<T>.prototype.getOrElse( value: T): T
95+
```typescript
96+
Maybe<T>.prototype.getOrElse( value: T): T
97+
```
9198

9299
Signature for *Result* is:
93100

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+
```
97104

98-
Maybe<T> itself represents a union type of Just<T> and None<T>.
105+
### Maybe
99106

100-
#### Maybe<T>(value: T | undefined | null) => Maybe<T>
107+
*Maybe<T>* itself represents a union type of Just<T> and None<T>.
101108

102109
It is also a *smart factory* which turns Nullable object to *Just<T>* or *None<T>* accordingly.
103110

104-
#### Just<T>
111+
```typescript
112+
Maybe<T>(value: T | undefined | null) => Maybe<T>
113+
```
105114

106-
Represents a value of specified type.
115+
#### Just
107116

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>*
109118

110-
Wraps a value with *Just<T>*
119+
```typescript
120+
Just<T>(value: T) => Maybe<T>
121+
```
111122

112-
#### None<T>
123+
#### None
113124

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.
115126

116-
#### None<T>() => Maybe<T>
127+
```typescript
128+
None<T>() => Maybe<T>
129+
```
117130

118-
Creates None of specified type.
131+
#### isJust
119132

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*
121134

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+
```
123152

124-
#### isNone<T>(obj: any): obj is Just<T>
153+
Moreover *Maybe* has a method dedicated to the same goal.
125154

126-
Checks wether object of any type is *None*
155+
```typescript
156+
Maybe<T>.prototype.isNone(): obj is Just<T>
157+
```
127158

159+
### Result
128160

161+
*Result<T, E>* itself represents a union type of Success<T, E> and Failure<T, E>.
129162

163+
It is also a *smart factory* which calls provided function and stores its output as *Success<T, E>* or *Failure<T, E>* accordingly.
130164

165+
```typescript
166+
Maybe<T, E extends Throwable>(action: () => T | Result<T, E>) => Result<T, E>
167+
```
131168
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+
```
132176
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+
```
133212
134213
## Contribution guidelines
135214
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
136246
247+
npm run test:ci
137248
249+
Everybody is welcome to contribute and submit pull requests. Please communicate your ideas and suggestions via *issues*.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "amonad",
3-
"version": "0.2.1",
3+
"version": "0.2.3",
44
"description": "Experimental implementation of Maybe and Result monads compatible with await.",
55
"main": "./dist/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)