Repository: gcanti/fp-ts
Pull request #1498 (2021-04-27 12:49:00)

Add rte chain reader either k
This P.R. add these methods in `ReaderTaskEither`:
- `fromReaderEitherK`
- `chainReaderEitherK` / `chainReaderEitherKW`
- `chainFirstReaderEitherK` / `chainFirstReaderEitherKW`

vinassefranche: @gcanti Tell me (if this gets merged) if you want me to create the same P.R. to 3.0.0

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4c287090..d266251e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -153,10 +153,13 @@ high state of flux, you're at risk of it changing without notice.
     - add `orElseFirst` / `orElseFirstW`
     - add `orLeft`
     - add `fromReaderTaskK`
+    - add `fromReaderEitherK`
     - add `chainReaderKW`
     - add `chainReaderTaskK`, `chainReaderTaskKW`
     - add `chainFirstReaderK`, `chainFirstReaderKW`
     - add `chainFirstReaderTaskK`, `chainFirstReaderTaskKW`
+    - add `chainReaderEitherK`, `chainReaderEitherKW`
+    - add `chainFirstReaderEitherK`, `chainFirstReaderEitherKW`
   - `ReadonlyArray`
     - add `prependW`, `appendW` (@thewilkybarkid)
     - add `filterE`
diff --git a/docs/modules/ReaderTaskEither.ts.md b/docs/modules/ReaderTaskEither.ts.md
index 108daaa8..b3185592 100644
--- a/docs/modules/ReaderTaskEither.ts.md
+++ b/docs/modules/ReaderTaskEither.ts.md
@@ -39,6 +39,8 @@ Added in v2.0.0
   - [chainEitherKW](#chaineitherkw)
   - [chainFirst](#chainfirst)
   - [chainFirstIOK](#chainfirstiok)
+  - [chainFirstReaderEitherK](#chainfirstreadereitherk)
+  - [chainFirstReaderEitherKW](#chainfirstreadereitherkw)
   - [chainFirstReaderK](#chainfirstreaderk)
   - [chainFirstReaderKW](#chainfirstreaderkw)
   - [chainFirstReaderTaskK](#chainfirstreadertaskk)
@@ -49,6 +51,8 @@ Added in v2.0.0
   - [chainIOEitherKW](#chainioeitherkw)
   - [chainIOK](#chainiok)
   - [chainOptionK](#chainoptionk)
+  - [chainReaderEitherK](#chainreadereitherk)
+  - [chainReaderEitherKW](#chainreadereitherkw)
   - [chainReaderK](#chainreaderk)
   - [chainReaderKW](#chainreaderkw)
   - [chainReaderTaskK](#chainreadertaskk)
@@ -64,6 +68,7 @@ Added in v2.0.0
   - [fromIOEitherK](#fromioeitherk)
   - [fromIOK](#fromiok)
   - [fromOptionK](#fromoptionk)
+  - [fromReaderEitherK](#fromreadereitherk)
   - [fromReaderK](#fromreaderk)
   - [fromReaderTaskK](#fromreadertaskk)
   - [fromTaskEitherK](#fromtaskeitherk)
@@ -434,6 +439,32 @@ export declare const chainFirstIOK: <A, B>(
 
 Added in v2.10.0
 
+## chainFirstReaderEitherK
+
+**Signature**
+
+```ts
+export declare const chainFirstReaderEitherK: <R, E, A, B>(
+  f: (a: A) => ReaderEither<R, E, B>
+) => (ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, A>
+```
+
+Added in v2.11.0
+
+## chainFirstReaderEitherKW
+
+Less strict version of [`chainFirstReaderEitherK`](#chainFirstReaderEitherK).
+
+**Signature**
+
+```ts
+export declare const chainFirstReaderEitherKW: <R2, E2, A, B>(
+  f: (a: A) => ReaderEither<R2, E2, B>
+) => <R1, E1>(ma: ReaderTaskEither<R1, E1, A>) => ReaderTaskEither<R1 & R2, E2 | E1, A>
+```
+
+Added in v2.11.0
+
 ## chainFirstReaderK
 
 **Signature**
@@ -564,6 +595,32 @@ export declare const chainOptionK: <E>(
 
 Added in v2.10.0
 
+## chainReaderEitherK
+
+**Signature**
+
+```ts
+export declare const chainReaderEitherK: <R, E, A, B>(
+  f: (a: A) => ReaderEither<R, E, B>
+) => (ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, B>
+```
+
+Added in v2.11.0
+
+## chainReaderEitherKW
+
+Less strict version of [`chainReaderEitherK`](#chainReaderEitherK).
+
+**Signature**
+
+```ts
+export declare const chainReaderEitherKW: <R2, E2, A, B>(
+  f: (a: A) => ReaderEither<R2, E2, B>
+) => <R1, E1>(ma: ReaderTaskEither<R1, E1, A>) => ReaderTaskEither<R1 & R2, E2 | E1, B>
+```
+
+Added in v2.11.0
+
 ## chainReaderK
 
 **Signature**
@@ -762,6 +819,18 @@ export declare const fromOptionK: <E>(
 
 Added in v2.10.0
 
+## fromReaderEitherK
+
+**Signature**
+
+```ts
+export declare const fromReaderEitherK: <R, E, A extends readonly unknown[], B>(
+  f: (...a: A) => ReaderEither<R, E, B>
+) => (...a: A) => ReaderTaskEither<R, E, B>
+```
+
+Added in v2.11.0
+
 ## fromReaderK
 
 **Signature**
diff --git a/src/ReaderTaskEither.ts b/src/ReaderTaskEither.ts
index 7a544859..2a86e492 100644
--- a/src/ReaderTaskEither.ts
+++ b/src/ReaderTaskEither.ts
@@ -453,6 +453,52 @@ export const chainTaskEitherK: <E, A, B>(
   f: (a: A) => TaskEither<E, B>
 ) => <R>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, B> = chainTaskEitherKW
 
+/**
+ * @category combinators
+ * @since 2.11.0
+ */
+export const fromReaderEitherK = <R, E, A extends ReadonlyArray<unknown>, B>(
+  f: (...a: A) => ReaderEither<R, E, B>
+): ((...a: A) => ReaderTaskEither<R, E, B>) => flow(f, fromReaderEither)
+
+/**
+ * Less strict version of [`chainReaderEitherK`](#chainReaderEitherK).
+ *
+ * @category combinators
+ * @since 2.11.0
+ */
+export const chainReaderEitherKW: <R2, E2, A, B>(
+  f: (a: A) => ReaderEither<R2, E2, B>
+) => <R1, E1>(ma: ReaderTaskEither<R1, E1, A>) => ReaderTaskEither<R1 & R2, E1 | E2, B> = (f) =>
+  chainW(fromReaderEitherK(f))
+
+/**
+ * @category combinators
+ * @since 2.11.0
+ */
+export const chainReaderEitherK: <R, E, A, B>(
+  f: (a: A) => ReaderEither<R, E, B>
+) => (ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, B> = chainReaderEitherKW
+
+/**
+ * Less strict version of [`chainFirstReaderEitherK`](#chainFirstReaderEitherK).
+ *
+ * @category combinators
+ * @since 2.11.0
+ */
+export const chainFirstReaderEitherKW: <R2, E2, A, B>(
+  f: (a: A) => ReaderEither<R2, E2, B>
+) => <R1, E1>(ma: ReaderTaskEither<R1, E1, A>) => ReaderTaskEither<R1 & R2, E1 | E2, A> = (f) =>
+  chainFirstW(fromReaderEitherK(f))
+
+/**
+ * @category combinators
+ * @since 2.11.0
+ */
+export const chainFirstReaderEitherK: <R, E, A, B>(
+  f: (a: A) => ReaderEither<R, E, B>
+) => (ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, A> = chainFirstReaderEitherKW
+
 // -------------------------------------------------------------------------------------
 // non-pipeables
 // -------------------------------------------------------------------------------------


Test patch:
diff --git a/test/ReaderTaskEither.ts b/test/ReaderTaskEither.ts
index 2aa88404..14b21d61 100644
--- a/test/ReaderTaskEither.ts
+++ b/test/ReaderTaskEither.ts
@@ -428,6 +428,16 @@ describe('ReaderTaskEither', () => {
     U.deepStrictEqual(await pipe(_.right<{}, never, string>('a'), _.chainFirstReaderTaskKW(f))({})(), E.right('a'))
   })
 
+  it('chainReaderEitherKW', async () => {
+    const f = (s: string) => RE.right(s.length)
+    U.deepStrictEqual(await pipe(_.right<{}, never, string>('a'), _.chainReaderEitherKW(f))({})(), E.right(1))
+  })
+
+  it('chainFirstReaderEitherKW', async () => {
+    const f = (s: string) => RE.right(s.length)
+    U.deepStrictEqual(await pipe(_.right<{}, never, string>('a'), _.chainFirstReaderEitherKW(f))({})(), E.right('a'))
+  })
+
   // -------------------------------------------------------------------------------------
   // utils
   // -------------------------------------------------------------------------------------