Skip to content

Commit

Permalink
Adjust casing of exports; add IOEither; fix test paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jdolle committed Feb 17, 2020
1 parent 127edee commit bb79bdb
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 35 deletions.
32 changes: 32 additions & 0 deletions docs/modules/IOEither.ts.md
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.
4 changes: 2 additions & 2 deletions docs/modules/either.ts.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: either.ts
title: Either.ts
nav_order: 1
parent: Modules
---

# either overview
# Either overview

Added in v0.0.1

Expand Down
29 changes: 20 additions & 9 deletions docs/modules/index.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,50 @@ Added in v0.0.1

<h2 class="text-delta">Table of contents</h2>

- [either](#either)
- [option](#option)
- [taskEither](#taskeither)
- [Either](#either)
- [IOEither](#ioeither)
- [Option](#option)
- [TaskEither](#taskeither)
- [util](#util)

---

# either
# Either

**Signature**

```ts
typeof either
typeof Either
```

Added in v0.0.1

# option
# IOEither

**Signature**

```ts
typeof option
typeof IOEither
```

Added in v1.0.0

# Option

**Signature**

```ts
typeof Option
```

Added in v0.0.1

# taskEither
# TaskEither

**Signature**

```ts
typeof taskEither
typeof TaskEither
```

Added in v0.0.1
Expand Down
6 changes: 3 additions & 3 deletions docs/modules/option.ts.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: option.ts
nav_order: 3
title: Option.ts
nav_order: 4
parent: Modules
---

# option overview
# Option overview

Added in v0.0.1

Expand Down
6 changes: 3 additions & 3 deletions docs/modules/taskEither.ts.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: taskEither.ts
nav_order: 4
title: TaskEither.ts
nav_order: 5
parent: Modules
---

# taskEither overview
# TaskEither overview

Added in v0.0.1

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/util.ts.md
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
---

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unfun-ts",
"version": "0.0.1",
"version": "1.0.0",
"description": "Practical helpers to unfunctionalize fp-ts types",
"main": "lib/index.js",
"scripts": {
Expand All @@ -10,7 +10,8 @@
"clean": "rimraf lib/*",
"prebuild": "yarn clean",
"format": "prettier --write \"{tests,mocks,src}/**/*.ts\"",
"format:check": "prettier --check \"{tests,mocks,src}/**/*.ts\""
"format:check": "prettier --check \"{tests,mocks,src}/**/*.ts\"",
"docs": "docs-ts"
},
"keywords": [
"fp-ts",
Expand Down
20 changes: 20 additions & 0 deletions src/IOEither.ts
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))
}
17 changes: 11 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@
* @since 0.0.1
*/

import * as either from './either'
import * as option from './option'
import * as taskEither from './taskEither'
import * as Either from './Either'
import * as Option from './Option'
import * as TaskEither from './TaskEither'
import * as IOEither from './IOEither'
import * as util from './util'

export {
/**
* @since 0.0.1
*/
either,
Either,
/**
* @since 0.0.1
*/
option,
Option,
/**
* @since 0.0.1
*/
taskEither,
TaskEither,
/**
* @since 1.0.0
*/
IOEither,
/**
* @since 0.0.1
*/
Expand Down
6 changes: 3 additions & 3 deletions tests/either/index.test.ts → tests/Either.test.ts
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"`)
})
})
19 changes: 19 additions & 0 deletions tests/IOEither.test.ts
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"`,
)
})
})
6 changes: 3 additions & 3 deletions tests/option/index.test.ts → tests/Option.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { option } from '../../src/index'
import { Option } from '../src/index'
import * as O from 'fp-ts/lib/Option'

function onNone() {
Expand All @@ -7,14 +7,14 @@ function onNone() {

describe('getOrThrow', () => {
it('should return the value when passed a Some', () => {
expect(option.getOrThrow(O.some('Success'), onNone)).toMatchInlineSnapshot(
expect(Option.getOrThrow(O.some('Success'), onNone)).toMatchInlineSnapshot(
`"Success"`,
)
})

it('should throw the left when passed a Left', () => {
expect(() =>
option.getOrThrow(O.none, onNone),
Option.getOrThrow(O.none, onNone),
).toThrowErrorMatchingInlineSnapshot(`"Nothing to be seen here"`)
})
})
6 changes: 3 additions & 3 deletions tests/taskEither/index.test.ts → tests/TaskEither.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { taskEither } from '../../src/index'
import { TaskEither } from '../src/index'
import * as TE from 'fp-ts/lib/TaskEither'
import * as E from 'fp-ts/lib/Either'

describe('toThrowingTask', () => {
it('should return a task that when called returns a Right', async () => {
const task = taskEither.toThrowingTask(TE.fromEither(E.right('Success')))
const task = TaskEither.toThrowingTask(TE.fromEither(E.right('Success')))
await expect(task()).resolves.toMatchInlineSnapshot(`"Success"`)
})

it('should return a task that when called throws the Left', async () => {
const task = taskEither.toThrowingTask(
const task = TaskEither.toThrowingTask(
TE.fromEither(E.left(new Error('Nothing to be seen here'))),
)
await expect(task()).rejects.toThrowErrorMatchingInlineSnapshot(
Expand Down

0 comments on commit bb79bdb

Please sign in to comment.