Repository: gcanti/fp-ts
Pull request #1485 (2021-04-19 10:32:31)

Add ReaderTaskEither.fromReaderTaskK, ReaderTaskEither.chainReaderTaskK and ReaderTaskEither.chainReaderTaskKW
This P.R. adds:
- `ReaderTaskEither.fromReaderTaskK`
- `ReaderTaskEither.chainReaderTaskK`
- `ReaderTaskEither.chainReaderTaskKW`





Patch:
diff --git a/docs/modules/ReaderTaskEither.ts.md b/docs/modules/ReaderTaskEither.ts.md
index 2cb41f0a..7ca8cdde 100644
--- a/docs/modules/ReaderTaskEither.ts.md
+++ b/docs/modules/ReaderTaskEither.ts.md
@@ -39,6 +39,8 @@ Added in v3.0.0
   - [chainIOK](#chainiok)
   - [chainOptionK](#chainoptionk)
   - [chainReaderK](#chainreaderk)
+  - [chainReaderTaskK](#chainreadertaskk)
+  - [chainReaderTaskKW](#chainreadertaskkw)
   - [chainTaskEitherK](#chaintaskeitherk)
   - [chainTaskEitherKW](#chaintaskeitherkw)
   - [chainTaskK](#chaintaskk)
@@ -50,6 +52,7 @@ Added in v3.0.0
   - [fromIOK](#fromiok)
   - [fromOptionK](#fromoptionk)
   - [fromReaderK](#fromreaderk)
+  - [fromReaderTaskK](#fromreadertaskk)
   - [fromTaskEitherK](#fromtaskeitherk)
   - [fromTaskK](#fromtaskk)
   - [orElse](#orelse)
@@ -414,6 +417,32 @@ export declare const chainReaderK: <A, R, B>(
 
 Added in v3.0.0
 
+## chainReaderTaskK
+
+**Signature**
+
+```ts
+export declare const chainReaderTaskK: <A, R, B>(
+  f: (a: A) => RT.ReaderTask<R, B>
+) => <E = never>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, B>
+```
+
+Added in v3.0.0
+
+## chainReaderTaskKW
+
+Less strict version of [`chainReaderTaskK`](#chainReaderTaskK).
+
+**Signature**
+
+```ts
+export declare const chainReaderTaskKW: <A, R2, B>(
+  f: (a: A) => RT.ReaderTask<R2, B>
+) => <R1, E = never>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R1 & R2, E, B>
+```
+
+Added in v3.0.0
+
 ## chainTaskEitherK
 
 **Signature**
@@ -554,6 +583,18 @@ export declare const fromReaderK: <A extends readonly unknown[], R, B>(
 
 Added in v3.0.0
 
+## fromReaderTaskK
+
+**Signature**
+
+```ts
+export declare const fromReaderTaskK: <A extends readonly unknown[], R, B>(
+  f: (...a: A) => RT.ReaderTask<R, B>
+) => <E = never>(...a: A) => ReaderTaskEither<R, E, B>
+```
+
+Added in v3.0.0
+
 ## fromTaskEitherK
 
 **Signature**
diff --git a/src/ReaderTaskEither.ts b/src/ReaderTaskEither.ts
index b12127df..69666705 100644
--- a/src/ReaderTaskEither.ts
+++ b/src/ReaderTaskEither.ts
@@ -833,6 +833,33 @@ export const chainReaderK: <A, R, B>(
   /*#__PURE__*/
   chainReaderK_(FromReader, Chain)
 
+/**
+ * @category combinators
+ * @since 3.0.0
+ */
+export const fromReaderTaskK = <A extends ReadonlyArray<unknown>, R, B>(
+  f: (...a: A) => ReaderTask<R, B>
+): (<E = never>(...a: A) => ReaderTaskEither<R, E, B>) => (...a) => rightReaderTask(f(...a))
+
+/**
+ * Less strict version of [`chainReaderTaskK`](#chainReaderTaskK).
+ *
+ * @category combinators
+ * @since 3.0.0
+ */
+export const chainReaderTaskKW: <A, R2, B>(
+  f: (a: A) => RT.ReaderTask<R2, B>
+) => <R1, E = never>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R1 & R2, E, B> = (f) =>
+  chainW(fromReaderTaskK(f))
+
+/**
+ * @category combinators
+ * @since 3.0.0
+ */
+export const chainReaderTaskK: <A, R, B>(
+  f: (a: A) => RT.ReaderTask<R, B>
+) => <E = never>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, B> = chainReaderTaskKW
+
 /**
  * @category instances
  * @since 3.0.0


Test patch:
diff --git a/test/ReaderTaskEither.ts b/test/ReaderTaskEither.ts
index 9cacb9ae..5fa3401c 100644
--- a/test/ReaderTaskEither.ts
+++ b/test/ReaderTaskEither.ts
@@ -344,6 +344,16 @@ describe('ReaderTaskEither', () => {
     U.deepStrictEqual(await pipe(_.right('a'), _.chainTaskEitherK(f))(undefined)(), E.right(1))
   })
 
+  it('chainReaderTaskK', async () => {
+    const f = flow(S.size, RT.of)
+    U.deepStrictEqual(await pipe(_.right('a'), _.chainReaderTaskK(f))(undefined)(), E.right(1))
+  })
+
+  it('chainReaderTaskKW', async () => {
+    const f = flow(S.size, RT.of)
+    U.deepStrictEqual(await pipe(_.right<string, {}, never>('a'), _.chainReaderTaskKW(f))({})(), E.right(1))
+  })
+
   // -------------------------------------------------------------------------------------
   // utils
   // -------------------------------------------------------------------------------------