Skip to content

Commit

Permalink
Allow dependencies to be widen when using orLeft
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid authored and gcanti committed May 19, 2024
1 parent a94d4f8 commit 909c7c6
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/modules/ReaderEither.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Added in v2.0.0
- [orElse](#orelse)
- [orElseW](#orelsew)
- [orLeft](#orleft)
- [orLeftW](#orleftw)
- [tapError](#taperror)
- [filtering](#filtering)
- [filterOrElse](#filterorelse)
Expand Down Expand Up @@ -652,6 +653,18 @@ export declare const orLeft: <E1, R, E2>(

Added in v2.11.0

## orLeftW

**Signature**

```ts
export declare const orLeftW: <E1, R2, E2>(
onLeft: (e: E1) => R.Reader<R2, E2>
) => <R1, A>(fa: ReaderEither<R1, E1, A>) => ReaderEither<R1 & R2, E2, A>
```

Added in v2.16.6

## tapError

Returns an effect that effectfully "peeks" at the failure of this effect.
Expand Down
13 changes: 13 additions & 0 deletions docs/modules/ReaderTaskEither.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Added in v2.0.0
- [orElse](#orelse)
- [orElseW](#orelsew)
- [orLeft](#orleft)
- [orLeftW](#orleftw)
- [tapError](#taperror)
- [filtering](#filtering)
- [filterOrElse](#filterorelse)
Expand Down Expand Up @@ -1038,6 +1039,18 @@ export declare const orLeft: <E1, R, E2>(

Added in v2.11.0

## orLeftW

**Signature**

```ts
export declare const orLeftW: <E1, R2, E2>(
onLeft: (e: E1) => RT.ReaderTask<R2, E2>
) => <R1, A>(fa: ReaderTaskEither<R1, E1, A>) => ReaderTaskEither<R1 & R2, E2, A>
```

Added in v2.16.6

## tapError

Returns an effect that effectfully "peeks" at the failure of this effect.
Expand Down
10 changes: 10 additions & 0 deletions dtslint/ts3.5/ReaderEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ pipe(
_.orLeft((a) => R.of(a.length))
)

//
// orLeftW
//

// $ExpectType ReaderEither<{ a: string; } & { b: string; }, number, never>
pipe(
_.left<{ a: string }, string, never>('a'),
_.orLeftW((a) => R.of<{ b: string }, number>(a.length))
)

//
// chainW
//
Expand Down
10 changes: 10 additions & 0 deletions dtslint/ts3.5/ReaderTaskEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ pipe(
_.orLeft((a) => RT.of(a.length))
)

//
// orLeftW
//

// $ExpectType ReaderTaskEither<{ a: string; } & { b: string; }, number, never>
pipe(
_.left<{ a: string }, string, never>('a'),
_.orLeftW((a) => RT.of<{ b: string }, number>(a.length))
)

//
// chainW
//
Expand Down
8 changes: 8 additions & 0 deletions src/ReaderEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,14 @@ export const orLeft: <E1, R, E2>(
onLeft: (e: E1) => Reader<R, E2>
) => <A>(fa: ReaderEither<R, E1, A>) => ReaderEither<R, E2, A> = /*#__PURE__*/ ET.orLeft(R.Monad)

/**
* @category error handling
* @since 2.16.6
*/
export const orLeftW: <E1, R2, E2>(
onLeft: (e: E1) => Reader<R2, E2>
) => <R1, A>(fa: ReaderEither<R1, E1, A>) => ReaderEither<R1 & R2, E2, A> = orLeft as any

/**
* @since 2.0.0
*/
Expand Down
8 changes: 8 additions & 0 deletions src/ReaderTaskEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,14 @@ export const orLeft: <E1, R, E2>(
onLeft: (e: E1) => ReaderTask<R, E2>
) => <A>(fa: ReaderTaskEither<R, E1, A>) => ReaderTaskEither<R, E2, A> = /*#__PURE__*/ ET.orLeft(RT.Monad)

/**
* @category error handling
* @since 2.16.6
*/
export const orLeftW: <E1, R2, E2>(
onLeft: (e: E1) => ReaderTask<R2, E2>
) => <R1, A>(fa: ReaderTaskEither<R1, E1, A>) => ReaderTaskEither<R1 & R2, E2, A> = orLeft as any

/**
* @since 2.0.0
*/
Expand Down
6 changes: 6 additions & 0 deletions test/ReaderEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ describe.concurrent('ReaderEither', () => {
U.deepStrictEqual(pipe(_.left('a'), f)({}), E.left('a!'))
})

it('orLeftW', () => {
const f = _.orLeftW((s: string) => R.of(s + '!'))
U.deepStrictEqual(pipe(_.right(1), f)({}), E.right(1))
U.deepStrictEqual(pipe(_.left('a'), f)({}), E.left('a!'))
})

describe.concurrent('getSemigroup', () => {
it('concat', () => {
const S = _.getSemigroup(N.SemigroupSum)
Expand Down
6 changes: 6 additions & 0 deletions test/ReaderTaskEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ describe.concurrent('ReaderTaskEither', () => {
U.deepStrictEqual(await pipe(_.left('a'), f)({})(), E.left('a!'))
})

it('orLeftW', async () => {
const f = _.orLeftW((s: string) => RT.of(s + '!'))
U.deepStrictEqual(await pipe(_.right(1), f)({})(), E.right(1))
U.deepStrictEqual(await pipe(_.left('a'), f)({})(), E.left('a!'))
})

describe.concurrent('MonadIO', () => {
it('fromIO', async () => {
U.deepStrictEqual(await _.fromIO(() => 1)({})(), E.right(1))
Expand Down

0 comments on commit 909c7c6

Please sign in to comment.