Skip to content

Commit

Permalink
remove async methods, change safeUnwrap to unsafeUnwrap.
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-potts committed Aug 16, 2024
1 parent c751a95 commit 99d4618
Show file tree
Hide file tree
Showing 3 changed files with 314 additions and 330 deletions.
34 changes: 0 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ import { ok, err, Result, ... } from 'resultwire'
- [mapErr](#maperr)
- [unwrapOr](#unwrapor)
- [andThen](#andthen)
- [asyncAndThen](#asyncandthen)
- [orElse](#orelse)
- [match](#match)
- [asyncMatch](#asyncmatch)
- [asyncMap](#asyncmap)
- [fromThrowable](#fromthrowable)
- [fromPromise](#frompromise)
- [combine](#combine)
Expand Down Expand Up @@ -143,16 +140,6 @@ const result = ok(42);
const chainedResult = andThen(result, (value) => ok(value * 2));
```

### asyncAndThen

Asynchronously chains a function that returns a ```Promise<Result>``` to the value of an ```Ok``` result.

**Example:**
```typescript
const result = ok(42);
const chainedResult = await asyncAndThen(result, async (value) => ok(value * 2));
```

### orElse

Chains a function that returns a ```Result``` to the error of an ```Err``` result.
Expand All @@ -172,27 +159,6 @@ Matches a ```Result``` against two functions, one for ```Ok``` and one for ```Er
const result = ok(42);
const matchedResult = match(result, (value) => value * 2, (error) => 0); // 84
```

### asyncMatch

Asynchronously matches a ```Result``` against two functions, one for ```Ok``` and one for ```Err```.

**Example:**
```typescript
const result = ok(42);
const matchedResult = await asyncMatch(result, async (value) => value * 2, async (error) => 0); // 84
```

### asyncMap

Asynchronously maps a function over the value of an ```Ok``` result.

**Example:**
```typescript
const result = ok(42);
const mappedResult = await asyncMap(result, async (value) => value * 2);
```

### fromThrowable

Executes a function that may throw an error and returns the result as a ```Result```.
Expand Down
15 changes: 6 additions & 9 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import {
andThen,
orElse,
match,
asyncAndThen,
asyncMatch,
asyncMap,
fromThrowable,
combine,
combineWithAllErrors,
Expand Down Expand Up @@ -138,15 +135,15 @@ describe('Result', () => {

it('should async chain a function that returns a Promise<Result> to the value of an Ok result', async () => {
const result = ok(42);
const chainedResult = await asyncAndThen(result, async (value) =>
const chainedResult = await andThen(result, async (value) =>
Promise.resolve(ok(value * 2)),
);
expect(chainedResult).toEqual({ kind: 'ok', value: 84 });
});

it('should not async chain a function to the value of an Err result', async () => {
const result = err('Something went wrong');
const chainedResult = await asyncAndThen(result, async () => {
const chainedResult = await andThen(result, async () => {
return Promise.reject('Should not be called');
}
);
Expand All @@ -155,7 +152,7 @@ describe('Result', () => {

it('should async match the Ok variant of a Result', async () => {
const result = ok(42);
const matchedValue = await asyncMatch(
const matchedValue = await match(
result,
async (value) => Promise.resolve(value * 2),
async () => Promise.resolve(0),
Expand All @@ -165,7 +162,7 @@ describe('Result', () => {

it('should async match the Err variant of a Result', async () => {
const result = err('Something went wrong');
const matchedValue = await asyncMatch(
const matchedValue = await match(
result,
async () => {
return Promise.reject('Should not be called');
Expand All @@ -177,15 +174,15 @@ describe('Result', () => {

it('should async map a function over the value of an Ok result', async () => {
const result = ok(42);
const mappedResult = await asyncMap(result, async (value) =>
const mappedResult = await map(result, async (value) =>
Promise.resolve(value * 2),
);
expect(mappedResult).toEqual({ kind: 'ok', value: 84 });
});

it('should not async map a function over the value of an Err result', async () => {
const result = err('Something went wrong');
const mappedResult = await asyncMap(result, async () => {
const mappedResult = await map(result, async () => {
throw new Error('Should not be called');
},
);
Expand Down
Loading

0 comments on commit 99d4618

Please sign in to comment.