Skip to content

Commit

Permalink
feat: tapReaderIO
Browse files Browse the repository at this point in the history
  • Loading branch information
sukovanej committed May 20, 2023
1 parent 456baa4 commit 553977d
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 32 deletions.
17 changes: 17 additions & 0 deletions docs/modules/ReaderTask.ts.md
Expand Up @@ -16,6 +16,7 @@ Added in v2.3.0
- [tap](#tap)
- [tapIO](#tapio)
- [tapReader](#tapreader)
- [tapReaderIO](#tapreaderio)
- [tapTask](#taptask)
- [constructors](#constructors)
- [ask](#ask)
Expand Down Expand Up @@ -183,6 +184,22 @@ export declare const tapReader: {

Added in v2.16.0

## tapReaderIO

Composes computations in sequence, using the return value of one computation to determine the next computation and
keeping only the result of the first.

**Signature**

```ts
export declare const tapReaderIO: {
<R1, R2, A, _>(self: ReaderTask<R1, A>, f: (a: A) => RIO.ReaderIO<R2, _>): ReaderTask<R1 & R2, A>
<R2, A, _>(f: (a: A) => RIO.ReaderIO<R2, _>): <R1>(self: ReaderTask<R1, A>) => ReaderTask<R1 & R2, A>
}
```

Added in v2.16.0

## tapTask

Composes computations in sequence, using the return value of one computation to determine the next computation and
Expand Down
79 changes: 51 additions & 28 deletions docs/modules/ReaderTaskEither.ts.md
Expand Up @@ -18,6 +18,7 @@ Added in v2.0.0
- [tapIO](#tapio)
- [tapReader](#tapreader)
- [tapReaderEither](#tapreadereither)
- [tapReaderIO](#tapreaderio)
- [tapReaderTask](#tapreadertask)
- [tapTask](#taptask)
- [tapTaskEither](#taptaskeither)
Expand Down Expand Up @@ -106,6 +107,8 @@ Added in v2.0.0
- [chainFirstIOK](#chainfirstiok)
- [chainFirstReaderEitherK](#chainfirstreadereitherk)
- [chainFirstReaderEitherKW](#chainfirstreadereitherkw)
- [chainFirstReaderIOK](#chainfirstreaderiok)
- [chainFirstReaderIOKW](#chainfirstreaderiokw)
- [chainFirstReaderK](#chainfirstreaderk)
- [chainFirstReaderKW](#chainfirstreaderkw)
- [chainFirstTaskEitherK](#chainfirsttaskeitherk)
Expand Down Expand Up @@ -149,8 +152,6 @@ Added in v2.0.0
- [matchEW](#matchew)
- [matchW](#matchw)
- [sequencing](#sequencing)
- [chainFirstReaderIOK](#chainfirstreaderiok)
- [chainFirstReaderIOKW](#chainfirstreaderiokw)
- [chainFirstReaderTaskK](#chainfirstreadertaskk)
- [chainFirstReaderTaskKW](#chainfirstreadertaskkw)
- [chainIOEitherK](#chainioeitherk)
Expand Down Expand Up @@ -344,6 +345,24 @@ export declare const tapReaderEither: {

Added in v2.16.0

## tapReaderIO

Composes computations in sequence, using the return value of one computation to determine the next computation and
keeping only the result of the first.

**Signature**

```ts
export declare const tapReaderIO: {
<R1, R2, E, A, _>(self: ReaderTaskEither<R1, E, A>, f: (a: A) => RIO.ReaderIO<R2, _>): ReaderTaskEither<R1 & R2, E, A>
<R2, A, _>(f: (a: A) => RT.ReaderTask<R2, _>): <R1, E>(
self: ReaderTaskEither<R1, E, A>
) => ReaderTaskEither<R1 & R2, E, A>
}
```

Added in v2.16.0

## tapReaderTask

Composes computations in sequence, using the return value of one computation to determine the next computation and
Expand Down Expand Up @@ -1442,6 +1461,36 @@ export declare const chainFirstReaderEitherKW: <R2, E2, A, B>(

Added in v2.11.0

## chainFirstReaderIOK

Alias of `tapReaderIO`.

**Signature**

```ts
export declare const chainFirstReaderIOK: <A, R, B>(
f: (a: A) => RIO.ReaderIO<R, B>
) => <E>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, A>
```

Added in v2.13.0

## chainFirstReaderIOKW

Alias of `tapReaderIO`.

Less strict version of [`chainFirstReaderIOK`](#chainfirstreaderiok).

**Signature**

```ts
export declare const chainFirstReaderIOKW: <A, R2, B>(
f: (a: A) => RIO.ReaderIO<R2, B>
) => <R1, E>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R1 & R2, E, A>
```

Added in v2.13.0

## chainFirstReaderK

Alias of `tapReader`.
Expand Down Expand Up @@ -1980,32 +2029,6 @@ Added in v2.10.0

# sequencing

## chainFirstReaderIOK

**Signature**

```ts
export declare const chainFirstReaderIOK: <A, R, B>(
f: (a: A) => RIO.ReaderIO<R, B>
) => <E>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, A>
```

Added in v2.13.0

## chainFirstReaderIOKW

Less strict version of [`chainFirstReaderIOK`](#chainfirstreaderiok).

**Signature**

```ts
export declare const chainFirstReaderIOKW: <A, R2, B>(
f: (a: A) => RIO.ReaderIO<R2, B>
) => <R1, E>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R1 & R2, E, A>
```

Added in v2.13.0

## chainFirstReaderTaskK

**Signature**
Expand Down
16 changes: 16 additions & 0 deletions src/ReaderTask.ts
Expand Up @@ -457,6 +457,22 @@ export const tapTask: {
<A, _>(f: (a: A) => Task<_>): <R>(self: ReaderTask<R, A>) => ReaderTask<R, A>
} = /*#__PURE__*/ dual(2, tapTask_(FromTask, Chain))

/**
* Composes computations in sequence, using the return value of one computation to determine the next computation and
* keeping only the result of the first.
*
* @category combinators
* @since 2.16.0
*/
export const tapReaderIO: {
<R1, R2, A, _>(self: ReaderTask<R1, A>, f: (a: A) => ReaderIO<R2, _>): ReaderTask<R1 & R2, A>
<R2, A, _>(f: (a: A) => ReaderIO<R2, _>): <R1>(self: ReaderTask<R1, A>) => ReaderTask<R1 & R2, A>
} = /*#__PURE__*/ dual(
2,
<R1, R2, A, _>(self: ReaderTask<R1, A>, f: (a: A) => ReaderIO<R2, _>): ReaderTask<R1 & R2, A> =>
tap(self, fromReaderIOK(f))
)

/**
* @category lifting
* @since 2.4.0
Expand Down
30 changes: 26 additions & 4 deletions src/ReaderTaskEither.ts
Expand Up @@ -1206,6 +1206,24 @@ export const tapReaderTask: {
): ReaderTaskEither<R1 & R2, E, A> => tap(self, fromReaderTaskK(f))
)

/**
* Composes computations in sequence, using the return value of one computation to determine the next computation and
* keeping only the result of the first.
*
* @category combinators
* @since 2.16.0
*/
export const tapReaderIO: {
<R1, R2, E, A, _>(self: ReaderTaskEither<R1, E, A>, f: (a: A) => ReaderIO<R2, _>): ReaderTaskEither<R1 & R2, E, A>
<R2, A, _>(f: (a: A) => ReaderTask<R2, _>): <R1, E>(
self: ReaderTaskEither<R1, E, A>
) => ReaderTaskEither<R1 & R2, E, A>
} = /*#__PURE__*/ dual(
2,
<R1, R2, E, A, _>(self: ReaderTaskEither<R1, E, A>, f: (a: A) => ReaderIO<R2, _>): ReaderTaskEither<R1 & R2, E, A> =>
tap(self, fromReaderIOK(f))
)

/**
* @category instances
* @since 2.7.0
Expand Down Expand Up @@ -1423,22 +1441,26 @@ export const chainReaderIOK: <A, R, B>(
) => <E>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, B> = chainReaderIOKW

/**
* Alias of `tapReaderIO`.
*
* Less strict version of [`chainFirstReaderIOK`](#chainfirstreaderiok).
*
* @category sequencing
* @category legacy
* @since 2.13.0
*/
export const chainFirstReaderIOKW: <A, R2, B>(
f: (a: A) => ReaderIO<R2, B>
) => <R1, E>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R1 & R2, E, A> = (f) => chainFirstW(fromReaderIOK(f))
) => <R1, E>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R1 & R2, E, A> = tapReaderIO

/**
* @category sequencing
* Alias of `tapReaderIO`.
*
* @category legacy
* @since 2.13.0
*/
export const chainFirstReaderIOK: <A, R, B>(
f: (a: A) => ReaderIO<R, B>
) => <E>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, A> = chainFirstReaderIOKW
) => <E>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, A> = tapReaderIO

/**
* @category conversions
Expand Down
4 changes: 4 additions & 0 deletions test/ReaderTask.ts
Expand Up @@ -315,4 +315,8 @@ describe.concurrent('ReaderTask', () => {
it('tapReader', async () => {
U.deepStrictEqual(await _.tapReader(_.of(1), () => R.of(2))({})(), 1)
})

it('tapReaderIO', async () => {
U.deepStrictEqual(await _.tapReaderIO(_.of(1), () => RIO.of(2))({})(), 1)
})
})
4 changes: 4 additions & 0 deletions test/ReaderTaskEither.ts
Expand Up @@ -786,4 +786,8 @@ describe.concurrent('ReaderTaskEither', () => {
it('tapReaderTask', async () => {
U.deepStrictEqual(await _.tapReaderTask(_.of(1), () => RT.of(2))({})(), E.of(1))
})

it('tapReaderIO', async () => {
U.deepStrictEqual(await _.tapReaderIO(_.of(1), () => RIO.of(2))({})(), E.of(1))
})
})

0 comments on commit 553977d

Please sign in to comment.