Repository: gcanti/fp-ts
Pull request #1500 (2021-04-30 14:36:17)

Add RTE.chainFirstTaskEitherK
We should have them all on ReaderTaskEither now!


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d799c89d..630d4cdd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -166,6 +166,7 @@ high state of flux, you're at risk of it changing without notice.
     - add `chainFirstReaderTaskK`, `chainFirstReaderTaskKW`
     - add `chainReaderEitherK`, `chainReaderEitherKW`
     - add `chainFirstReaderEitherK`, `chainFirstReaderEitherKW`
+    - add `chainFirstTaskEitherK`, `chainFirstTaskEitherKW`
     - add `flattenW`
   - `ReadonlyArray`
     - add `prependW`, `appendW` (@thewilkybarkid)
diff --git a/docs/modules/ReaderTaskEither.ts.md b/docs/modules/ReaderTaskEither.ts.md
index 0e2049ff..30fea3c2 100644
--- a/docs/modules/ReaderTaskEither.ts.md
+++ b/docs/modules/ReaderTaskEither.ts.md
@@ -45,6 +45,8 @@ Added in v2.0.0
   - [chainFirstReaderKW](#chainfirstreaderkw)
   - [chainFirstReaderTaskK](#chainfirstreadertaskk)
   - [chainFirstReaderTaskKW](#chainfirstreadertaskkw)
+  - [chainFirstTaskEitherK](#chainfirsttaskeitherk)
+  - [chainFirstTaskEitherKW](#chainfirsttaskeitherkw)
   - [chainFirstTaskK](#chainfirsttaskk)
   - [chainFirstW](#chainfirstw)
   - [chainIOEitherK](#chainioeitherk)
@@ -519,6 +521,32 @@ export declare const chainFirstReaderTaskKW: <A, R2, B>(
 
 Added in v2.11.0
 
+## chainFirstTaskEitherK
+
+**Signature**
+
+```ts
+export declare const chainFirstTaskEitherK: <E, A, B>(
+  f: (a: A) => TE.TaskEither<E, B>
+) => <R>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, A>
+```
+
+Added in v2.11.0
+
+## chainFirstTaskEitherKW
+
+Less strict version of [`chainFirstTaskEitherK`](#chainFirstTaskEitherK).
+
+**Signature**
+
+```ts
+export declare const chainFirstTaskEitherKW: <E2, A, B>(
+  f: (a: A) => TE.TaskEither<E2, B>
+) => <R, E1>(ma: ReaderTaskEither<R, E1, A>) => ReaderTaskEither<R, E2 | E1, A>
+```
+
+Added in v2.11.0
+
 ## chainFirstTaskK
 
 **Signature**
diff --git a/src/ReaderTaskEither.ts b/src/ReaderTaskEither.ts
index dd897439..c4438b54 100644
--- a/src/ReaderTaskEither.ts
+++ b/src/ReaderTaskEither.ts
@@ -457,6 +457,24 @@ export const chainTaskEitherK: <E, A, B>(
   f: (a: A) => TaskEither<E, B>
 ) => <R>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, B> = chainTaskEitherKW
 
+/**
+ * Less strict version of [`chainFirstTaskEitherK`](#chainFirstTaskEitherK).
+ *
+ * @category combinators
+ * @since 2.11.0
+ */
+export const chainFirstTaskEitherKW: <E2, A, B>(
+  f: (a: A) => TaskEither<E2, B>
+) => <R, E1>(ma: ReaderTaskEither<R, E1, A>) => ReaderTaskEither<R, E1 | E2, A> = (f) => chainFirstW(fromTaskEitherK(f))
+
+/**
+ * @category combinators
+ * @since 2.11.0
+ */
+export const chainFirstTaskEitherK: <E, A, B>(
+  f: (a: A) => TaskEither<E, B>
+) => <R>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, A> = chainFirstTaskEitherKW
+
 /**
  * @category combinators
  * @since 2.11.0


Test patch:
diff --git a/test/ReaderTaskEither.ts b/test/ReaderTaskEither.ts
index 31b3ee0c..49537374 100644
--- a/test/ReaderTaskEither.ts
+++ b/test/ReaderTaskEither.ts
@@ -428,6 +428,11 @@ describe('ReaderTaskEither', () => {
     U.deepStrictEqual(await pipe(_.right('a'), _.chainTaskEitherK(f))(undefined)(), E.right(1))
   })
 
+  it('chainFirstTaskEitherKW', async () => {
+    const f = (s: string) => TE.right<string, number>(s.length)
+    U.deepStrictEqual(await pipe(_.right<{}, number, string>('a'), _.chainFirstTaskEitherKW(f))({})(), E.right('a'))
+  })
+
   it('chainReaderTaskK', async () => {
     const f = flow(S.size, RT.of)
     U.deepStrictEqual(await pipe(_.right('a'), _.chainReaderTaskK(f))(undefined)(), E.right(1))