Skip to content

Commit

Permalink
Improve README with more precise comparisons with Promises.
Browse files Browse the repository at this point in the history
  • Loading branch information
Galileo Sanchez committed Jun 18, 2019
1 parent 5ca8af4 commit 178b629
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions README.md
Expand Up @@ -855,7 +855,7 @@ Future.of(1)
//> 2
```

For comparison, the equivalent with Promises is:
For comparison, an approximation with Promises is:

```js
Promise.resolve(1)
Expand Down Expand Up @@ -890,12 +890,18 @@ Future.reject('error')
//! "error!"
```

For comparison, the equivalent with Promises is:
For comparison, an approximation with Promises is:

```js
Promise.resolve(1)
.then(x => x + 1, x => x + '!')
.then(x => x + 1, x => Promise.reject(x + '!'))
.then(console.log, console.error);
//> 2

Promise.reject('error')
.then(x => x + 1, x => Promise.reject(x + '!'))
.then(console.log, console.error);
//! "error!"
```

#### chain
Expand Down Expand Up @@ -927,12 +933,13 @@ Future.of(1)
//> 2
```

For comparison, the equivalent with Promises is:
For comparison, an approximation with Promises is:

```js
Promise.resolve(1)
.then(x => Promise.resolve(x + 1))
.then(console.log, console.error);
//> 2
```

#### swap
Expand Down Expand Up @@ -977,12 +984,13 @@ Future.reject(new Error('It broke!'))
//! [Oh No! It broke!]
```

For comparison, the equivalent with Promises is:
For comparison, an approximation with Promises is:

```js
Promise.resolve(1)
Promise.reject(new Error('It broke!'))
.then(null, err => Promise.reject(new Error('Oh No! ' + err.message)))
.then(console.log, console.error);
//! [Oh No! It broke!]
```

#### chainRej
Expand All @@ -1006,7 +1014,7 @@ Future.reject(new Error('It broke!'))
//> "It broke! But it's all good."
```

For comparison, the equivalent with Promises is:
For comparison, an approximation with Promises is:

```js
Promise.reject(new Error('It broke!'))
Expand Down Expand Up @@ -1044,12 +1052,18 @@ Future.reject('it broke')
//> Left('it broke')
```

For comparison, the equivalent with Promises is:
For comparison, an approximation with Promises is:

```js
Promise.resolve('hello')
.then(S.Right, S.Left)
.then(console.log);
//> Right('hello')

Promise.reject('it broke')
.then(S.Right, S.Left)
.then(console.log);
//> Left('it broke')
```

### Combining Futures
Expand Down

0 comments on commit 178b629

Please sign in to comment.