Skip to content

Commit b349dbc

Browse files
Add apFirstW and apSecondW to ReaderTask (#1958)
1 parent 669cd3e commit b349dbc

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

docs/modules/ReaderTask.ts.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ Added in v2.3.0
105105
- [ApT](#apt)
106106
- [ap](#ap)
107107
- [apFirst](#apfirst)
108+
- [apFirstW](#apfirstw)
108109
- [apSecond](#apsecond)
110+
- [apSecondW](#apsecondw)
109111
- [apW](#apw)
110112
- [local](#local)
111113
- [zone of death](#zone-of-death)
@@ -1191,6 +1193,22 @@ export declare const apFirst: <E, B>(second: ReaderTask<E, B>) => <A>(first: Rea
11911193
11921194
Added in v2.3.0
11931195
1196+
## apFirstW
1197+
1198+
Less strict version of [`apFirst`](#apfirst).
1199+
1200+
The `W` suffix (short for **W**idening) means that the environment types will be merged.
1201+
1202+
**Signature**
1203+
1204+
```ts
1205+
export declare const apFirstW: <R2, B>(
1206+
second: ReaderTask<R2, B>
1207+
) => <R1, A>(first: ReaderTask<R1, A>) => ReaderTask<R1 & R2, A>
1208+
```
1209+
1210+
Added in v2.17.0
1211+
11941212
## apSecond
11951213
11961214
Combine two effectful actions, keeping only the result of the second.
@@ -1203,6 +1221,22 @@ export declare const apSecond: <E, B>(second: ReaderTask<E, B>) => <A>(first: Re
12031221
12041222
Added in v2.3.0
12051223
1224+
## apSecondW
1225+
1226+
Less strict version of [`apSecond`](#apsecond).
1227+
1228+
The `W` suffix (short for **W**idening) means that the environment types will be merged.
1229+
1230+
**Signature**
1231+
1232+
```ts
1233+
export declare const apSecondW: <R2, B>(
1234+
second: ReaderTask<R2, B>
1235+
) => <R1, A>(first: ReaderTask<R1, A>) => ReaderTask<R1 & R2, B>
1236+
```
1237+
1238+
Added in v2.17.0
1239+
12061240
## apW
12071241
12081242
Less strict version of [`ap`](#ap).

src/ReaderTask.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,35 @@ export const ApplyPar: Apply2<URI> = {
252252
*/
253253
export const apFirst = /*#__PURE__*/ apFirst_(ApplyPar)
254254

255+
/**
256+
* Less strict version of [`apFirst`](#apfirst).
257+
*
258+
* The `W` suffix (short for **W**idening) means that the environment types will be merged.
259+
*
260+
* @since 2.17.0
261+
*/
262+
export const apFirstW: <R2, B>(
263+
second: ReaderTask<R2, B>
264+
) => <R1, A>(first: ReaderTask<R1, A>) => ReaderTask<R1 & R2, A> = apFirst as any
265+
255266
/**
256267
* Combine two effectful actions, keeping only the result of the second.
257268
*
258269
* @since 2.3.0
259270
*/
260271
export const apSecond = /*#__PURE__*/ apSecond_(ApplyPar)
261272

273+
/**
274+
* Less strict version of [`apSecond`](#apsecond).
275+
*
276+
* The `W` suffix (short for **W**idening) means that the environment types will be merged.
277+
*
278+
* @since 2.17.0
279+
*/
280+
export const apSecondW: <R2, B>(
281+
second: ReaderTask<R2, B>
282+
) => <R1, A>(first: ReaderTask<R1, A>) => ReaderTask<R1 & R2, B> = apSecond as any
283+
262284
/**
263285
* Runs computations in parallel.
264286
*

test/ReaderTask.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,22 @@ describe('ReaderTask', () => {
2828
U.deepStrictEqual(await pipe(_.of('a'), _.apFirst(_.of('b')))({})(), 'a')
2929
})
3030

31+
it('apFirstW', async () => {
32+
const fa = _.of<{ readonly k: string }, string>('a')
33+
const fb = _.of<{ readonly x: number }, boolean>(true)
34+
U.deepStrictEqual(await pipe(fa, _.apFirstW(fb))({ k: 'v', x: 42 })(), 'a')
35+
})
36+
3137
it('apSecond', async () => {
3238
U.deepStrictEqual(await pipe(_.of('a'), _.apSecond(_.of('b')))({})(), 'b')
3339
})
3440

41+
it('apSecondW', async () => {
42+
const fa = _.of<{ readonly k: string }, string>('a')
43+
const fb = _.of<{ readonly x: number }, boolean>(true)
44+
U.deepStrictEqual(await pipe(fa, _.apSecondW(fb))({ k: 'v', x: 42 })(), true)
45+
})
46+
3547
it('flatMap', async () => {
3648
const f = (a: string) => _.of(a.length)
3749
U.deepStrictEqual(await pipe(_.of('foo'), _.flatMap(f))({})(), 3)

0 commit comments

Comments
 (0)