-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust casing of exports; add IOEither; fix test paths
- Loading branch information
Showing
13 changed files
with
123 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
title: IOEither.ts | ||
nav_order: 3 | ||
parent: Modules | ||
--- | ||
|
||
# IOEither overview | ||
|
||
Added in v1.0.0 | ||
|
||
Helpers for IOEithers | ||
|
||
--- | ||
|
||
<h2 class="text-delta">Table of contents</h2> | ||
|
||
- [toThrowingIO](#tothrowingio) | ||
|
||
--- | ||
|
||
# toThrowingIO | ||
|
||
**Signature** | ||
|
||
```ts | ||
export function toThrowingIO<E, A>( | ||
ioe: IOE.IOEither<E, A>, | ||
): IO.IO<A> { ... } | ||
``` | ||
|
||
Added in v0.0.1 | ||
Converts a IOEither to a IO. If the IOEither is a left, this IO will throw the left value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
title: util.ts | ||
nav_order: 5 | ||
nav_order: 6 | ||
parent: Modules | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @since 1.0.0 | ||
* | ||
* Helpers for IOEithers | ||
*/ | ||
|
||
import * as IOE from 'fp-ts/lib/IOEither' | ||
import * as IO from 'fp-ts/lib/IO' | ||
import { pipe } from 'fp-ts/lib/pipeable' | ||
import { throwError } from './util' | ||
|
||
/** | ||
* @since 0.0.1 | ||
* Converts a IOEither to a IO. If the IOEither is a left, this IO will throw the left value. | ||
*/ | ||
export function toThrowingIO<E, A>( | ||
ioe: IOE.IOEither<E, A>, | ||
): IO.IO<A> { | ||
return pipe(ioe, IOE.fold(throwError, IO.of)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import { either } from '../../src/index' | ||
import { Either } from '../src/index' | ||
import * as E from 'fp-ts/lib/Either' | ||
|
||
describe('getOrThrow', () => { | ||
it('should return the value when passed a Right', () => { | ||
expect(either.getOrThrow(E.right('Success'))).toMatchInlineSnapshot( | ||
expect(Either.getOrThrow(E.right('Success'))).toMatchInlineSnapshot( | ||
`"Success"`, | ||
) | ||
}) | ||
|
||
it('should throw the left when passed a Left', () => { | ||
expect(() => | ||
either.getOrThrow(E.left(new Error('Kaput'))), | ||
Either.getOrThrow(E.left(new Error('Kaput'))), | ||
).toThrowErrorMatchingInlineSnapshot(`"Kaput"`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { IOEither } from '../src/index' | ||
import * as IOE from 'fp-ts/lib/IOEither' | ||
import * as E from 'fp-ts/lib/Either' | ||
|
||
describe('toThrowingIO', () => { | ||
it('should return a io that when called returns a Right', async () => { | ||
const io = IOEither.toThrowingIO(IOE.fromEither(E.right('Success'))) | ||
await expect(io()).toMatchInlineSnapshot(`"Success"`) | ||
}) | ||
|
||
it('should return a io that when called throws the Left', async () => { | ||
const io = IOEither.toThrowingIO( | ||
IOE.fromEither(E.left(new Error('Nothing to be seen here'))), | ||
) | ||
await expect(io).toThrowErrorMatchingInlineSnapshot( | ||
`"Nothing to be seen here"`, | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters