From 9b4218fa4d31b680160046f67e6bdf8fbe0d7d19 Mon Sep 17 00:00:00 2001 From: gcanti Date: Tue, 2 May 2023 17:19:03 +0200 Subject: [PATCH 1/5] IOEither: add tapError --- src/EitherT.ts | 20 +++++++++++++++++++- src/IOEither.ts | 39 ++++++++++++++++++++++++++------------- test/IOEither.ts | 10 ++++++++++ 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/EitherT.ts b/src/EitherT.ts index fe053eb64..b5691761c 100644 --- a/src/EitherT.ts +++ b/src/EitherT.ts @@ -655,8 +655,26 @@ export function orElseFirst( export function orElseFirst( M: Monad ): (onLeft: (e: E) => HKT>) => (ma: HKT>) => HKT> { + const tapErrorM = tapError(M) + return (onLeft) => (ma) => tapErrorM(ma, onLeft) +} + +/** @internal */ +export function tapError( + M: Monad1 +): (ma: Kind>, onLeft: (e: E) => Kind>) => Kind> +export function tapError( + M: Monad +): (ma: HKT>, onLeft: (e: E) => HKT>) => HKT> +export function tapError( + M: Monad +): (ma: HKT>, onLeft: (e: E) => HKT>) => HKT> { const orElseM = orElse(M) - return (onLeft) => orElseM((e) => M.map(onLeft(e), (eb) => (E.isLeft(eb) ? eb : E.left(e)))) + return (ma, onLeft) => + pipe( + ma, + orElseM((e) => M.map(onLeft(e), (eb) => (E.isLeft(eb) ? eb : E.left(e)))) + ) } /** diff --git a/src/IOEither.ts b/src/IOEither.ts index 837081b47..e0c101c64 100644 --- a/src/IOEither.ts +++ b/src/IOEither.ts @@ -245,28 +245,22 @@ export const orElseW: ( ) => (ma: IOEither) => IOEither = orElse as any /** - * @category error handling - * @since 2.11.0 - */ -export const orElseFirst: (onLeft: (e: E) => IOEither) => (ma: IOEither) => IOEither = - /*#__PURE__*/ ET.orElseFirst(I.Monad) - -/** - * The `W` suffix (short for **W**idening) means that the error types will be merged. + * Returns an effect that effectfully "peeks" at the failure of this effect. * * @category error handling - * @since 2.11.0 + * @since 1.0.0 */ -export const orElseFirstW: ( - onLeft: (e: E1) => IOEither -) => (ma: IOEither) => IOEither = orElseFirst as any +export const tapError: { + (onLeft: (e: E1) => IOEither): (self: IOEither) => IOEither + (self: IOEither, onLeft: (e: E1) => IOEither): IOEither +} = dual(2, ET.tapError(I.Monad)) /** * @category error handling * @since 2.12.0 */ export const orElseFirstIOK: (onLeft: (e: E) => IO) => (ma: IOEither) => IOEither = (onLeft) => - orElseFirst(fromIOK(onLeft)) + tapError(fromIOK(onLeft)) /** * @category error handling @@ -1107,6 +1101,25 @@ export const chainFirstW: ( f: (a: A) => IOEither ) => (ma: IOEither) => IOEither = tap +/** + * Alias of `tapError`. + * + * @category legacy + * @since 2.11.0 + */ +export const orElseFirst: (onLeft: (e: E) => IOEither) => (ma: IOEither) => IOEither = + tapError + +/** + * Alias of `tapError`. + * + * @category legacy + * @since 2.11.0 + */ +export const orElseFirstW: ( + onLeft: (e: E1) => IOEither +) => (ma: IOEither) => IOEither = tapError + // ------------------------------------------------------------------------------------- // deprecated // ------------------------------------------------------------------------------------- diff --git a/test/IOEither.ts b/test/IOEither.ts index d7f975401..0de3e5827 100644 --- a/test/IOEither.ts +++ b/test/IOEither.ts @@ -286,6 +286,16 @@ describe.concurrent('IOEither', () => { U.deepStrictEqual(_.orElseW(() => _.right(2))(_.right(1))(), E.right(1)) }) + it('tapError', () => { + const f = (e: string) => (e.length <= 1 ? _.right(true) : _.left(e + '!')) + U.deepStrictEqual(pipe(_.right(1), _.tapError(f))(), E.right(1)) + U.deepStrictEqual(pipe(_.left('a'), _.tapError(f))(), E.left('a')) + U.deepStrictEqual(pipe(_.left('aa'), _.tapError(f))(), E.left('aa!')) + U.deepStrictEqual(_.tapError(_.right(1), f)(), E.right(1)) + U.deepStrictEqual(_.tapError(_.left('a'), f)(), E.left('a')) + U.deepStrictEqual(_.tapError(_.left('aa'), f)(), E.left('aa!')) + }) + it('orElseFirst', () => { const f = _.orElseFirst((e: string) => (e.length <= 1 ? _.right(true) : _.left(e + '!'))) U.deepStrictEqual(pipe(_.right(1), f)(), E.right(1)) From a9e8c61d949e0e8d1ba6472f84b03b8af9635825 Mon Sep 17 00:00:00 2001 From: gcanti Date: Tue, 2 May 2023 17:22:37 +0200 Subject: [PATCH 2/5] TaskEither: add tapError --- src/IOEither.ts | 2 +- src/TaskEither.ts | 41 +++++++++++++++++++++++++++-------------- test/TaskEither.ts | 10 ++++++++++ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/IOEither.ts b/src/IOEither.ts index e0c101c64..e05f14c41 100644 --- a/src/IOEither.ts +++ b/src/IOEither.ts @@ -248,7 +248,7 @@ export const orElseW: ( * Returns an effect that effectfully "peeks" at the failure of this effect. * * @category error handling - * @since 1.0.0 + * @since 2.15.0 */ export const tapError: { (onLeft: (e: E1) => IOEither): (self: IOEither) => IOEither diff --git a/src/TaskEither.ts b/src/TaskEither.ts index c19d7e0f1..b64cb3f2a 100644 --- a/src/TaskEither.ts +++ b/src/TaskEither.ts @@ -350,21 +350,15 @@ export const orElseW: ( ) => (ma: TaskEither) => TaskEither = orElse as any /** - * @category error handling - * @since 2.11.0 - */ -export const orElseFirst: (onLeft: (e: E) => TaskEither) => (ma: TaskEither) => TaskEither = - /*#__PURE__*/ ET.orElseFirst(T.Monad) - -/** - * The `W` suffix (short for **W**idening) means that the error types will be merged. + * Returns an effect that effectfully "peeks" at the failure of this effect. * * @category error handling - * @since 2.11.0 + * @since 2.15.0 */ -export const orElseFirstW: ( - onLeft: (e: E1) => TaskEither -) => (ma: TaskEither) => TaskEither = orElseFirst as any +export const tapError: { + (onLeft: (e: E1) => TaskEither): (self: TaskEither) => TaskEither + (self: TaskEither, onLeft: (e: E1) => TaskEither): TaskEither +} = dual(2, ET.tapError(T.Monad)) /** * @category error handling @@ -372,7 +366,7 @@ export const orElseFirstW: ( */ export const orElseFirstIOK: (onLeft: (e: E) => IO) => (ma: TaskEither) => TaskEither = ( onLeft -) => orElseFirst(fromIOK(onLeft)) +) => tapError(fromIOK(onLeft)) /** * @category error handling @@ -380,7 +374,7 @@ export const orElseFirstIOK: (onLeft: (e: E) => IO) => (ma: TaskEith */ export const orElseFirstTaskK: (onLeft: (e: E) => Task) => (ma: TaskEither) => TaskEither = ( onLeft -) => orElseFirst(fromTaskK(onLeft)) +) => tapError(fromTaskK(onLeft)) /** * @category error handling @@ -1464,6 +1458,25 @@ export const chainFirstW: ( f: (a: A) => TaskEither ) => (ma: TaskEither) => TaskEither = tap +/** + * Alias of `tapError`. + * + * @category legacy + * @since 2.11.0 + */ +export const orElseFirst: (onLeft: (e: E) => TaskEither) => (ma: TaskEither) => TaskEither = + tapError + +/** + * Alias of `tapError`. + * + * @category legacy + * @since 2.11.0 + */ +export const orElseFirstW: ( + onLeft: (e: E1) => TaskEither +) => (ma: TaskEither) => TaskEither = tapError + // ------------------------------------------------------------------------------------- // deprecated // ------------------------------------------------------------------------------------- diff --git a/test/TaskEither.ts b/test/TaskEither.ts index 78d7ca18c..0357c5c31 100644 --- a/test/TaskEither.ts +++ b/test/TaskEither.ts @@ -472,6 +472,16 @@ describe.concurrent('TaskEither', () => { ) }) + it('tapError', async () => { + const f = (e: string) => (e.length <= 1 ? _.right(true) : _.left(e + '!')) + U.deepStrictEqual(await pipe(_.right(1), _.tapError(f))(), E.right(1)) + U.deepStrictEqual(await pipe(_.left('a'), _.tapError(f))(), E.left('a')) + U.deepStrictEqual(await pipe(_.left('aa'), _.tapError(f))(), E.left('aa!')) + U.deepStrictEqual(await _.tapError(_.right(1), f)(), E.right(1)) + U.deepStrictEqual(await _.tapError(_.left('a'), f)(), E.left('a')) + U.deepStrictEqual(await _.tapError(_.left('aa'), f)(), E.left('aa!')) + }) + it('orElseFirst', async () => { const f = _.orElseFirst((e: string) => (e.length <= 1 ? _.right(true) : _.left(e + '!'))) U.deepStrictEqual(await pipe(_.right(1), f)(), E.right(1)) From 55dc1fc149c81234cc36248f1e009941d378d9ea Mon Sep 17 00:00:00 2001 From: gcanti Date: Tue, 2 May 2023 17:29:58 +0200 Subject: [PATCH 3/5] ReaderEither: add tapError --- src/EitherT.ts | 4 ++++ src/ReaderEither.ts | 45 +++++++++++++++++++++++++++++++------------- test/ReaderEither.ts | 10 ++++++++++ 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/EitherT.ts b/src/EitherT.ts index b5691761c..59d480f6b 100644 --- a/src/EitherT.ts +++ b/src/EitherT.ts @@ -659,6 +659,10 @@ export function orElseFirst( return (onLeft) => (ma) => tapErrorM(ma, onLeft) } +/** @internal */ +export function tapError( + M: Monad2 +): (ma: Kind2>, onLeft: (e: E) => Kind2>) => Kind2> /** @internal */ export function tapError( M: Monad1 diff --git a/src/ReaderEither.ts b/src/ReaderEither.ts index 869e32dc2..2cfcec8d8 100644 --- a/src/ReaderEither.ts +++ b/src/ReaderEither.ts @@ -257,22 +257,21 @@ export const orElseW: ( ) => (ma: ReaderEither) => ReaderEither = orElse as any /** - * @category error handling - * @since 2.11.0 - */ -export const orElseFirst: ( - onLeft: (e: E) => ReaderEither -) => (ma: ReaderEither) => ReaderEither = /*#__PURE__*/ ET.orElseFirst(R.Monad) - -/** - * The `W` suffix (short for **W**idening) means that the environment types and the return types will be merged. + * Returns an effect that effectfully "peeks" at the failure of this effect. * * @category error handling - * @since 2.11.0 + * @since 2.15.0 */ -export const orElseFirstW: ( - onLeft: (e: E1) => ReaderEither -) => (ma: ReaderEither) => ReaderEither = orElseFirst as any +export const tapError: { + (onLeft: (e: E1) => ReaderEither): ( + self: ReaderEither + ) => ReaderEither + (self: ReaderEither, onLeft: (e: E1) => ReaderEither): ReaderEither< + R1 & R2, + E1 | E2, + A + > +} = dual(2, ET.tapError(R.Monad)) /** * @category error handling @@ -1049,6 +1048,26 @@ export const chainFirstW: ( f: (a: A) => ReaderEither ) => (ma: ReaderEither) => ReaderEither = tap +/** + * Alias of `tapError`. + * + * @category legacy + * @since 2.11.0 + */ +export const orElseFirst: ( + onLeft: (e: E) => ReaderEither +) => (ma: ReaderEither) => ReaderEither = tapError + +/** + * Alias of `tapError`. + * + * @category legacy + * @since 2.11.0 + */ +export const orElseFirstW: ( + onLeft: (e: E1) => ReaderEither +) => (ma: ReaderEither) => ReaderEither = tapError + // ------------------------------------------------------------------------------------- // deprecated // ------------------------------------------------------------------------------------- diff --git a/test/ReaderEither.ts b/test/ReaderEither.ts index a3b207a26..d3a59895f 100644 --- a/test/ReaderEither.ts +++ b/test/ReaderEither.ts @@ -171,6 +171,16 @@ describe.concurrent('ReaderEither', () => { U.deepStrictEqual(orElse(_.right(1))({}), E.right(1)) }) + it('tapError', () => { + const f = (s: string) => (s.length <= 1 ? _.right(true) : _.left(s + '!')) + U.deepStrictEqual(pipe(_.right(1), _.tapError(f))({}), E.right(1)) + U.deepStrictEqual(pipe(_.left('a'), _.tapError(f))({}), E.left('a')) + U.deepStrictEqual(pipe(_.left('aa'), _.tapError(f))({}), E.left('aa!')) + U.deepStrictEqual(_.tapError(_.right(1), f)({}), E.right(1)) + U.deepStrictEqual(_.tapError(_.left('a'), f)({}), E.left('a')) + U.deepStrictEqual(_.tapError(_.left('aa'), f)({}), E.left('aa!')) + }) + it('orElseFirst', () => { const f = _.orElseFirst((s: string) => (s.length <= 1 ? _.right(true) : _.left(s + '!'))) U.deepStrictEqual(pipe(_.right(1), f)({}), E.right(1)) From c4d5788f1e5151b6b42d5daa6451c445e4940ef4 Mon Sep 17 00:00:00 2001 From: gcanti Date: Tue, 2 May 2023 17:37:24 +0200 Subject: [PATCH 4/5] ReaderTaskEither: add tapError --- src/EitherT.ts | 2 ++ src/ReaderTaskEither.ts | 44 ++++++++++++++++++++++++++++------------ test/ReaderTaskEither.ts | 10 +++++++++ 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/EitherT.ts b/src/EitherT.ts index 59d480f6b..0cd2d32b9 100644 --- a/src/EitherT.ts +++ b/src/EitherT.ts @@ -667,9 +667,11 @@ export function tapError( export function tapError( M: Monad1 ): (ma: Kind>, onLeft: (e: E) => Kind>) => Kind> +/** @internal */ export function tapError( M: Monad ): (ma: HKT>, onLeft: (e: E) => HKT>) => HKT> +/** @internal */ export function tapError( M: Monad ): (ma: HKT>, onLeft: (e: E) => HKT>) => HKT> { diff --git a/src/ReaderTaskEither.ts b/src/ReaderTaskEither.ts index 34e050e75..db8fd1335 100644 --- a/src/ReaderTaskEither.ts +++ b/src/ReaderTaskEither.ts @@ -413,22 +413,20 @@ export const orElseW: ( ) => (ma: ReaderTaskEither) => ReaderTaskEither = orElse as any /** - * @category error handling - * @since 2.11.0 - */ -export const orElseFirst: ( - onLeft: (e: E) => ReaderTaskEither -) => (ma: ReaderTaskEither) => ReaderTaskEither = /*#__PURE__*/ ET.orElseFirst(RT.Monad) - -/** - * The `W` suffix (short for **W**idening) means that the environment types and the return types will be merged. + * Returns an effect that effectfully "peeks" at the failure of this effect. * * @category error handling - * @since 2.11.0 + * @since 2.15.0 */ -export const orElseFirstW: ( - onLeft: (e: E1) => ReaderTaskEither -) => (ma: ReaderTaskEither) => ReaderTaskEither = orElseFirst as any +export const tapError: { + (onLeft: (e: E1) => ReaderTaskEither): ( + self: ReaderTaskEither + ) => ReaderTaskEither + ( + self: ReaderTaskEither, + onLeft: (e: E1) => ReaderTaskEither + ): ReaderTaskEither +} = dual(2, ET.tapError(RT.Monad)) /** * @category error handling @@ -1662,6 +1660,26 @@ export const chainFirstW: ( f: (a: A) => ReaderTaskEither ) => (ma: ReaderTaskEither) => ReaderTaskEither = tap +/** + * Alias of `tapError`. + * + * @category legacy + * @since 2.11.0 + */ +export const orElseFirst: ( + onLeft: (e: E) => ReaderTaskEither +) => (ma: ReaderTaskEither) => ReaderTaskEither = tapError + +/** + * Alias of `tapError`. + * + * @category legacy + * @since 2.11.0 + */ +export const orElseFirstW: ( + onLeft: (e: E1) => ReaderTaskEither +) => (ma: ReaderTaskEither) => ReaderTaskEither = tapError + // ------------------------------------------------------------------------------------- // deprecated // ------------------------------------------------------------------------------------- diff --git a/test/ReaderTaskEither.ts b/test/ReaderTaskEither.ts index 4cc8d3006..853d68018 100644 --- a/test/ReaderTaskEither.ts +++ b/test/ReaderTaskEither.ts @@ -316,6 +316,16 @@ describe.concurrent('ReaderTaskEither', () => { ) }) + it('tapError', async () => { + const f = (s: string) => (s.length <= 1 ? _.right(true) : _.left(s + '!')) + U.deepStrictEqual(await pipe(_.right(1), _.tapError(f))({})(), E.right(1)) + U.deepStrictEqual(await pipe(_.left('a'), _.tapError(f))({})(), E.left('a')) + U.deepStrictEqual(await pipe(_.left('aa'), _.tapError(f))({})(), E.left('aa!')) + U.deepStrictEqual(await pipe(_.tapError(_.right(1), f))({})(), E.right(1)) + U.deepStrictEqual(await pipe(_.tapError(_.left('a'), f))({})(), E.left('a')) + U.deepStrictEqual(await pipe(_.tapError(_.left('aa'), f))({})(), E.left('aa!')) + }) + it('orElseFirst', async () => { const f = _.orElseFirst((s: string) => (s.length <= 1 ? _.right(true) : _.left(s + '!'))) U.deepStrictEqual(await pipe(_.right(1), f)({})(), E.right(1)) From b64297d5735361435c0d95be8e59913bdb628fdb Mon Sep 17 00:00:00 2001 From: gcanti Date: Tue, 2 May 2023 17:39:00 +0200 Subject: [PATCH 5/5] update docs --- docs/modules/IOEither.ts.md | 70 +++++++++++++++---------- docs/modules/ReaderEither.ts.md | 80 +++++++++++++++++++---------- docs/modules/ReaderTaskEither.ts.md | 79 ++++++++++++++++++---------- docs/modules/TaskEither.ts.md | 74 ++++++++++++++++---------- 4 files changed, 193 insertions(+), 110 deletions(-) diff --git a/docs/modules/IOEither.ts.md b/docs/modules/IOEither.ts.md index b5aaceb4a..0493d39d9 100644 --- a/docs/modules/IOEither.ts.md +++ b/docs/modules/IOEither.ts.md @@ -48,11 +48,10 @@ Added in v2.0.0 - [getOrElseW](#getorelsew) - [mapLeft](#mapleft) - [orElse](#orelse) - - [orElseFirst](#orelsefirst) - [orElseFirstIOK](#orelsefirstiok) - - [orElseFirstW](#orelsefirstw) - [orElseW](#orelsew) - [orLeft](#orleft) + - [tapError](#taperror) - [filtering](#filtering) - [filterOrElse](#filterorelse) - [filterOrElseW](#filterorelsew) @@ -80,6 +79,8 @@ Added in v2.0.0 - [chainFirst](#chainfirst) - [chainFirstW](#chainfirstw) - [chainW](#chainw) + - [orElseFirst](#orelsefirst) + - [orElseFirstW](#orelsefirstw) - [lifting](#lifting) - [fromEitherK](#fromeitherk) - [fromIOK](#fromiok) @@ -458,16 +459,6 @@ export declare const orElse: (onLeft: (e: E1) => IOEither) => Added in v2.0.0 -## orElseFirst - -**Signature** - -```ts -export declare const orElseFirst: (onLeft: (e: E) => IOEither) => (ma: IOEither) => IOEither -``` - -Added in v2.11.0 - ## orElseFirstIOK **Signature** @@ -478,20 +469,6 @@ export declare const orElseFirstIOK: (onLeft: (e: E) => I.IO) => (ma Added in v2.12.0 -## orElseFirstW - -The `W` suffix (short for **W**idening) means that the error types will be merged. - -**Signature** - -```ts -export declare const orElseFirstW: ( - onLeft: (e: E1) => IOEither -) => (ma: IOEither) => IOEither -``` - -Added in v2.11.0 - ## orElseW Less strict version of [`orElse`](#orelse). @@ -518,6 +495,21 @@ export declare const orLeft: (onLeft: (e: E1) => I.IO) => (fa: IO Added in v2.11.0 +## tapError + +Returns an effect that effectfully "peeks" at the failure of this effect. + +**Signature** + +```ts +export declare const tapError: { + (onLeft: (e: E1) => IOEither): (self: IOEither) => IOEither + (self: IOEither, onLeft: (e: E1) => IOEither): IOEither +} +``` + +Added in v2.15.0 + # filtering ## filterOrElse @@ -799,6 +791,32 @@ export declare const chainW: ( Added in v2.6.0 +## orElseFirst + +Alias of `tapError`. + +**Signature** + +```ts +export declare const orElseFirst: (onLeft: (e: E) => IOEither) => (ma: IOEither) => IOEither +``` + +Added in v2.11.0 + +## orElseFirstW + +Alias of `tapError`. + +**Signature** + +```ts +export declare const orElseFirstW: ( + onLeft: (e: E1) => IOEither +) => (ma: IOEither) => IOEither +``` + +Added in v2.11.0 + # lifting ## fromEitherK diff --git a/docs/modules/ReaderEither.ts.md b/docs/modules/ReaderEither.ts.md index 4bc06e9f5..339c6375a 100644 --- a/docs/modules/ReaderEither.ts.md +++ b/docs/modules/ReaderEither.ts.md @@ -46,10 +46,9 @@ Added in v2.0.0 - [getOrElseW](#getorelsew) - [mapLeft](#mapleft) - [orElse](#orelse) - - [orElseFirst](#orelsefirst) - - [orElseFirstW](#orelsefirstw) - [orElseW](#orelsew) - [orLeft](#orleft) + - [tapError](#taperror) - [filtering](#filtering) - [filterOrElse](#filterorelse) - [filterOrElseW](#filterorelsew) @@ -72,6 +71,8 @@ Added in v2.0.0 - [chainFirst](#chainfirst) - [chainFirstW](#chainfirstw) - [chainW](#chainw) + - [orElseFirst](#orelsefirst) + - [orElseFirstW](#orelsefirstw) - [lifting](#lifting) - [fromEitherK](#fromeitherk) - [fromOptionK](#fromoptionk) @@ -519,32 +520,6 @@ export declare const orElse: ( Added in v2.0.0 -## orElseFirst - -**Signature** - -```ts -export declare const orElseFirst: ( - onLeft: (e: E) => ReaderEither -) => (ma: ReaderEither) => ReaderEither -``` - -Added in v2.11.0 - -## orElseFirstW - -The `W` suffix (short for **W**idening) means that the environment types and the return types will be merged. - -**Signature** - -```ts -export declare const orElseFirstW: ( - onLeft: (e: E1) => ReaderEither -) => (ma: ReaderEither) => ReaderEither -``` - -Added in v2.11.0 - ## orElseW Less strict version of [`orElse`](#orelse). @@ -573,6 +548,27 @@ export declare const orLeft: ( Added in v2.11.0 +## tapError + +Returns an effect that effectfully "peeks" at the failure of this effect. + +**Signature** + +```ts +export declare const tapError: { + (onLeft: (e: E1) => ReaderEither): ( + self: ReaderEither + ) => ReaderEither + (self: ReaderEither, onLeft: (e: E1) => ReaderEither): ReaderEither< + R1 & R2, + E1 | E2, + A + > +} +``` + +Added in v2.15.0 + # filtering ## filterOrElse @@ -807,6 +803,34 @@ export declare const chainW: ( Added in v2.6.0 +## orElseFirst + +Alias of `tapError`. + +**Signature** + +```ts +export declare const orElseFirst: ( + onLeft: (e: E) => ReaderEither +) => (ma: ReaderEither) => ReaderEither +``` + +Added in v2.11.0 + +## orElseFirstW + +Alias of `tapError`. + +**Signature** + +```ts +export declare const orElseFirstW: ( + onLeft: (e: E1) => ReaderEither +) => (ma: ReaderEither) => ReaderEither +``` + +Added in v2.11.0 + # lifting ## fromEitherK diff --git a/docs/modules/ReaderTaskEither.ts.md b/docs/modules/ReaderTaskEither.ts.md index d75247eaa..d6b20ab08 100644 --- a/docs/modules/ReaderTaskEither.ts.md +++ b/docs/modules/ReaderTaskEither.ts.md @@ -60,10 +60,9 @@ Added in v2.0.0 - [getOrElseW](#getorelsew) - [mapLeft](#mapleft) - [orElse](#orelse) - - [orElseFirst](#orelsefirst) - - [orElseFirstW](#orelsefirstw) - [orElseW](#orelsew) - [orLeft](#orleft) + - [tapError](#taperror) - [filtering](#filtering) - [filterOrElse](#filterorelse) - [filterOrElseW](#filterorelsew) @@ -93,6 +92,8 @@ Added in v2.0.0 - [chainFirst](#chainfirst) - [chainFirstW](#chainfirstw) - [chainW](#chainw) + - [orElseFirst](#orelsefirst) + - [orElseFirstW](#orelsefirstw) - [lifting](#lifting) - [fromEitherK](#fromeitherk) - [fromIOEitherK](#fromioeitherk) @@ -727,32 +728,6 @@ export declare const orElse: ( Added in v2.0.0 -## orElseFirst - -**Signature** - -```ts -export declare const orElseFirst: ( - onLeft: (e: E) => ReaderTaskEither -) => (ma: ReaderTaskEither) => ReaderTaskEither -``` - -Added in v2.11.0 - -## orElseFirstW - -The `W` suffix (short for **W**idening) means that the environment types and the return types will be merged. - -**Signature** - -```ts -export declare const orElseFirstW: ( - onLeft: (e: E1) => ReaderTaskEither -) => (ma: ReaderTaskEither) => ReaderTaskEither -``` - -Added in v2.11.0 - ## orElseW Less strict version of [`orElse`](#orelse). @@ -781,6 +756,26 @@ export declare const orLeft: ( Added in v2.11.0 +## tapError + +Returns an effect that effectfully "peeks" at the failure of this effect. + +**Signature** + +```ts +export declare const tapError: { + (onLeft: (e: E1) => ReaderTaskEither): ( + self: ReaderTaskEither + ) => ReaderTaskEither + ( + self: ReaderTaskEither, + onLeft: (e: E1) => ReaderTaskEither + ): ReaderTaskEither +} +``` + +Added in v2.15.0 + # filtering ## filterOrElse @@ -1097,6 +1092,34 @@ export declare const chainW: ( Added in v2.6.0 +## orElseFirst + +Alias of `tapError`. + +**Signature** + +```ts +export declare const orElseFirst: ( + onLeft: (e: E) => ReaderTaskEither +) => (ma: ReaderTaskEither) => ReaderTaskEither +``` + +Added in v2.11.0 + +## orElseFirstW + +Alias of `tapError`. + +**Signature** + +```ts +export declare const orElseFirstW: ( + onLeft: (e: E1) => ReaderTaskEither +) => (ma: ReaderTaskEither) => ReaderTaskEither +``` + +Added in v2.11.0 + # lifting ## fromEitherK diff --git a/docs/modules/TaskEither.ts.md b/docs/modules/TaskEither.ts.md index b5a9951ca..1a6b7704e 100644 --- a/docs/modules/TaskEither.ts.md +++ b/docs/modules/TaskEither.ts.md @@ -55,12 +55,11 @@ Added in v2.0.0 - [getOrElseW](#getorelsew) - [mapLeft](#mapleft) - [orElse](#orelse) - - [orElseFirst](#orelsefirst) - [orElseFirstIOK](#orelsefirstiok) - [orElseFirstTaskK](#orelsefirsttaskk) - - [orElseFirstW](#orelsefirstw) - [orElseW](#orelsew) - [orLeft](#orleft) + - [tapError](#taperror) - [filtering](#filtering) - [filterOrElse](#filterorelse) - [filterOrElseW](#filterorelsew) @@ -92,6 +91,8 @@ Added in v2.0.0 - [chainFirst](#chainfirst) - [chainFirstW](#chainfirstw) - [chainW](#chainw) + - [orElseFirst](#orelsefirst) + - [orElseFirstW](#orelsefirstw) - [lifting](#lifting) - [fromEitherK](#fromeitherk) - [fromIOEitherK](#fromioeitherk) @@ -645,18 +646,6 @@ test() Added in v2.0.0 -## orElseFirst - -**Signature** - -```ts -export declare const orElseFirst: ( - onLeft: (e: E) => TaskEither -) => (ma: TaskEither) => TaskEither -``` - -Added in v2.11.0 - ## orElseFirstIOK **Signature** @@ -679,20 +668,6 @@ export declare const orElseFirstTaskK: ( Added in v2.12.0 -## orElseFirstW - -The `W` suffix (short for **W**idening) means that the error types will be merged. - -**Signature** - -```ts -export declare const orElseFirstW: ( - onLeft: (e: E1) => TaskEither -) => (ma: TaskEither) => TaskEither -``` - -Added in v2.11.0 - ## orElseW Less strict version of [`orElse`](#orelse). @@ -719,6 +694,21 @@ export declare const orLeft: (onLeft: (e: E1) => T.Task) => (fa: Added in v2.11.0 +## tapError + +Returns an effect that effectfully "peeks" at the failure of this effect. + +**Signature** + +```ts +export declare const tapError: { + (onLeft: (e: E1) => TaskEither): (self: TaskEither) => TaskEither + (self: TaskEither, onLeft: (e: E1) => TaskEither): TaskEither +} +``` + +Added in v2.15.0 + # filtering ## filterOrElse @@ -1098,6 +1088,34 @@ export declare const chainW: ( Added in v2.6.0 +## orElseFirst + +Alias of `tapError`. + +**Signature** + +```ts +export declare const orElseFirst: ( + onLeft: (e: E) => TaskEither +) => (ma: TaskEither) => TaskEither +``` + +Added in v2.11.0 + +## orElseFirstW + +Alias of `tapError`. + +**Signature** + +```ts +export declare const orElseFirstW: ( + onLeft: (e: E1) => TaskEither +) => (ma: TaskEither) => TaskEither +``` + +Added in v2.11.0 + # lifting ## fromEitherK