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 bd54421 commit 8f35bd9
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 34 deletions.
21 changes: 21 additions & 0 deletions docs/modules/ReaderTask.ts.md
Original file line number Diff line number Diff line change
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 Expand Up @@ -787,6 +804,8 @@ Added in v2.3.0

## chainFirstReaderIOK

Alias of `tapReaderIO`.

**Signature**

```ts
Expand All @@ -799,6 +818,8 @@ Added in v2.13.0
## chainFirstReaderIOKW
Alias of `tapReaderIO`.
Less strict version of [`chainFirstReaderIOK`](#chainfirstreaderiok).
**Signature**
Expand Down
79 changes: 51 additions & 28 deletions docs/modules/ReaderTaskEither.ts.md
Original file line number Diff line number Diff line change
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)
- [chainFirstReaderTaskK](#chainfirstreadertaskk)
Expand Down Expand Up @@ -151,8 +154,6 @@ Added in v2.0.0
- [matchEW](#matchew)
- [matchW](#matchw)
- [sequencing](#sequencing)
- [chainFirstReaderIOK](#chainfirstreaderiok)
- [chainFirstReaderIOKW](#chainfirstreaderiokw)
- [chainIOEitherK](#chainioeitherk)
- [chainIOEitherKW](#chainioeitherkw)
- [chainIOK](#chainiok)
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 @@ -2012,32 +2061,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

## chainIOEitherK

**Signature**
Expand Down
24 changes: 22 additions & 2 deletions src/ReaderTask.ts
Original file line number Diff line number Diff line change
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 Expand Up @@ -573,21 +589,25 @@ export const chainReaderIOK: <A, R, B>(f: (a: A) => ReaderIO<R, B>) => (ma: Read
chainReaderIOKW

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

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

/**
* @category lifting
Expand Down
30 changes: 26 additions & 4 deletions src/ReaderTaskEither.ts
Original file line number Diff line number Diff line change
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 @@ -1427,22 +1445,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 8f35bd9

Please sign in to comment.