Skip to content

Commit bcc2272

Browse files
Allow Reader's local to infer the environment type
1 parent 0805fbb commit bcc2272

18 files changed

+220
-12
lines changed

docs/modules/Reader.ts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ Changes the value of the local context during the execution of the action `ma` (
315315
**Signature**
316316
317317
```ts
318-
export declare const local: <R2, R1>(f: (r2: R2) => R1) => <A>(ma: Reader<R1, A>) => Reader<R2, A>
318+
export declare const local: <R1, R2 = R1>(f: (r2: R2) => R1) => <A>(ma: Reader<R1, A>) => Reader<R2, A>
319319
```
320320
321321
Added in v3.0.0

docs/modules/ReaderEither.ts.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,9 @@ Changes the value of the local context during the execution of the action `ma` (
531531
**Signature**
532532
533533
```ts
534-
export declare const local: <R2, R1>(f: (r2: R2) => R1) => <E, A>(ma: ReaderEither<R1, E, A>) => ReaderEither<R2, E, A>
534+
export declare const local: <R1, R2 = R1>(
535+
f: (r2: R2) => R1
536+
) => <E, A>(ma: ReaderEither<R1, E, A>) => ReaderEither<R2, E, A>
535537
```
536538
537539
Added in v3.0.0

docs/modules/ReaderIO.ts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ Changes the value of the local context during the execution of the action `ma` (
387387
**Signature**
388388
389389
```ts
390-
export declare const local: <R2, R1>(f: (r2: R2) => R1) => <A>(ma: ReaderIO<R1, A>) => ReaderIO<R2, A>
390+
export declare const local: <R1, R2 = R1>(f: (r2: R2) => R1) => <A>(ma: ReaderIO<R1, A>) => ReaderIO<R2, A>
391391
```
392392
393393
Added in v3.0.0

docs/modules/ReaderTask.ts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ Changes the value of the local context during the execution of the action `ma` (
338338
**Signature**
339339
340340
```ts
341-
export declare const local: <R2, R1>(f: (r2: R2) => R1) => <A>(ma: ReaderTask<R1, A>) => ReaderTask<R2, A>
341+
export declare const local: <R1, R2 = R1>(f: (r2: R2) => R1) => <A>(ma: ReaderTask<R1, A>) => ReaderTask<R2, A>
342342
```
343343
344344
Added in v3.0.0

docs/modules/ReaderTaskEither.ts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ Changes the value of the local context during the execution of the action `ma` (
880880
**Signature**
881881
882882
```ts
883-
export declare const local: <R2, R1>(
883+
export declare const local: <R1, R2 = R1>(
884884
f: (r2: R2) => R1
885885
) => <E, A>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R2, E, A>
886886
```

docs/modules/StateReaderTaskEither.ts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ Changes the value of the local context during the execution of the action `ma` (
770770
**Signature**
771771
772772
```ts
773-
export declare const local: <R2, R1>(
773+
export declare const local: <R1, R2 = R1>(
774774
f: (r2: R2) => R1
775775
) => <S, E, A>(ma: StateReaderTaskEither<S, R1, E, A>) => StateReaderTaskEither<S, R2, E, A>
776776
```

dtslint/ts4.1/Reader.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
11
import * as _ from '../../src/Reader'
22
import { pipe } from '../../src/function'
33

4+
declare function modifyA<R extends { a: string }>(r: R): R
5+
6+
//
7+
// local
8+
//
9+
10+
// $ExpectType Reader<{ a: string; }, string>
11+
pipe(
12+
_.of<string, { a: string }>('a'),
13+
_.local((env) => ({
14+
a: env.a
15+
}))
16+
)
17+
18+
// $ExpectType Reader<{ b: string; }, string>
19+
pipe(
20+
_.of<string, { a: string }>('a'),
21+
_.local((env: { b: string }) => ({
22+
a: env.b
23+
}))
24+
)
25+
26+
// $ExpectType Reader<{ b: string; }, string>
27+
pipe(
28+
_.of<string, { a: string; b: string }>('a'),
29+
_.local((env: { b: string }) => ({
30+
...env,
31+
a: env.b
32+
}))
33+
)
34+
35+
// $ExpectType Reader<{ a: string; b: string; }, string>
36+
pipe(_.of<string, { a: string; b: string }>('a'), _.local(modifyA))
37+
438
//
539
// chainW
640
//

dtslint/ts4.1/ReaderEither.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,40 @@ import * as R from '../../src/Reader'
33
import * as E from '../../src/Either'
44
import { pipe } from '../../src/function'
55

6+
declare function modifyA<R extends { a: string }>(r: R): R
7+
8+
//
9+
// local
10+
//
11+
12+
// $ExpectType ReaderEither<{ a: string; }, number, string>
13+
pipe(
14+
_.of<string, { a: string }, number>('a'),
15+
_.local((env) => ({
16+
a: env.a
17+
}))
18+
)
19+
20+
// $ExpectType ReaderEither<{ b: string; }, number, string>
21+
pipe(
22+
_.of<string, { a: string }, number>('a'),
23+
_.local((env: { b: string }) => ({
24+
a: env.b
25+
}))
26+
)
27+
28+
// $ExpectType ReaderEither<{ b: string; }, number, string>
29+
pipe(
30+
_.of<string, { a: string; b: string }, number>('a'),
31+
_.local((env: { b: string }) => ({
32+
...env,
33+
a: env.b
34+
}))
35+
)
36+
37+
// $ExpectType ReaderEither<{ a: string; b: string; }, number, string>
38+
pipe(_.of<string, { a: string; b: string }, number>('a'), _.local(modifyA))
39+
640
//
741
// getOrElseW
842
//

dtslint/ts4.1/ReaderIO.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as _ from '../../src/ReaderIO'
2+
import { pipe } from '../../src/function'
3+
4+
declare function modifyA<R extends { a: string }>(r: R): R
5+
6+
//
7+
// local
8+
//
9+
10+
// $ExpectType ReaderIO<{ a: string; }, string>
11+
pipe(
12+
_.of<string, { a: string }>('a'),
13+
_.local((env) => ({
14+
a: env.a
15+
}))
16+
)
17+
18+
// $ExpectType ReaderIO<{ b: string; }, string>
19+
pipe(
20+
_.of<string, { a: string }>('a'),
21+
_.local((env: { b: string }) => ({
22+
a: env.b
23+
}))
24+
)
25+
26+
// $ExpectType ReaderIO<{ b: string; }, string>
27+
pipe(
28+
_.of<string, { a: string; b: string }>('a'),
29+
_.local((env: { b: string }) => ({
30+
...env,
31+
a: env.b
32+
}))
33+
)
34+
35+
// $ExpectType ReaderIO<{ a: string; b: string; }, string>
36+
pipe(_.of<string, { a: string; b: string }>('a'), _.local(modifyA))

dtslint/ts4.1/ReaderTask.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
11
import * as _ from '../../src/ReaderTask'
22
import { pipe } from '../../src/function'
33

4+
declare function modifyA<R extends { a: string }>(r: R): R
5+
6+
//
7+
// local
8+
//
9+
10+
// $ExpectType ReaderTask<{ a: string; }, string>
11+
pipe(
12+
_.of<string, { a: string }>('a'),
13+
_.local((env) => ({
14+
a: env.a
15+
}))
16+
)
17+
18+
// $ExpectType ReaderTask<{ b: string; }, string>
19+
pipe(
20+
_.of<string, { a: string }>('a'),
21+
_.local((env: { b: string }) => ({
22+
a: env.b
23+
}))
24+
)
25+
26+
// $ExpectType ReaderTask<{ b: string; }, string>
27+
pipe(
28+
_.of<string, { a: string; b: string }>('a'),
29+
_.local((env: { b: string }) => ({
30+
...env,
31+
a: env.b
32+
}))
33+
)
34+
35+
// $ExpectType ReaderTask<{ a: string; b: string; }, string>
36+
pipe(_.of<string, { a: string; b: string }>('a'), _.local(modifyA))
37+
438
//
539
// Do
640
//

dtslint/ts4.1/ReaderTaskEither.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,40 @@ import * as TE from '../../src/TaskEither'
55
import * as IOE from '../../src/IOEither'
66
import { pipe } from '../../src/function'
77

8+
declare function modifyA<R extends { a: string }>(r: R): R
9+
10+
//
11+
// local
12+
//
13+
14+
// $ExpectType ReaderTaskEither<{ a: string; }, number, string>
15+
pipe(
16+
_.of<string, { a: string }, number>('a'),
17+
_.local((env) => ({
18+
a: env.a
19+
}))
20+
)
21+
22+
// $ExpectType ReaderTaskEither<{ b: string; }, number, string>
23+
pipe(
24+
_.of<string, { a: string }, number>('a'),
25+
_.local((env: { b: string }) => ({
26+
a: env.b
27+
}))
28+
)
29+
30+
// $ExpectType ReaderTaskEither<{ b: string; }, number, string>
31+
pipe(
32+
_.of<string, { a: string; b: string }, number>('a'),
33+
_.local((env: { b: string }) => ({
34+
...env,
35+
a: env.b
36+
}))
37+
)
38+
39+
// $ExpectType ReaderTaskEither<{ a: string; b: string; }, number, string>
40+
pipe(_.of<string, { a: string; b: string }, number>('a'), _.local(modifyA))
41+
842
//
943
// getOrElseW
1044
//

dtslint/ts4.1/StateReaderTaskEither.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,40 @@ import * as RTE from '../../src/ReaderTaskEither'
55
import * as IOE from '../../src/IOEither'
66
import { pipe } from '../../src/function'
77

8+
declare function modifyA<R extends { a: string }>(r: R): R
9+
10+
//
11+
// local
12+
//
13+
14+
// $ExpectType StateReaderTaskEither<boolean, { a: string; }, number, string>
15+
pipe(
16+
_.of<string, boolean, { a: string }, number>('a'),
17+
_.local((env) => ({
18+
a: env.a
19+
}))
20+
)
21+
22+
// $ExpectType StateReaderTaskEither<boolean, { b: string; }, number, string>
23+
pipe(
24+
_.of<string, boolean, { a: string }, number>('a'),
25+
_.local((env: { b: string }) => ({
26+
a: env.b
27+
}))
28+
)
29+
30+
// $ExpectType StateReaderTaskEither<boolean, { b: string; }, number, string>
31+
pipe(
32+
_.of<string, boolean, { a: string; b: string }, number>('a'),
33+
_.local((env: { b: string }) => ({
34+
...env,
35+
a: env.b
36+
}))
37+
)
38+
39+
// $ExpectType StateReaderTaskEither<boolean, { a: string; b: string; }, number, string>
40+
pipe(_.of<string, boolean, { a: string; b: string }, number>('a'), _.local(modifyA))
41+
842
//
943
// chainW
1044
//

src/Reader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const asksReader: <R, A>(f: (r: R) => Reader<R, A>) => Reader<R, A> = ask
7676
* @category combinators
7777
* @since 3.0.0
7878
*/
79-
export const local = <R2, R1>(f: (r2: R2) => R1) => <A>(ma: Reader<R1, A>): Reader<R2, A> => (r2) => ma(f(r2))
79+
export const local = <R1, R2 = R1>(f: (r2: R2) => R1) => <A>(ma: Reader<R1, A>): Reader<R2, A> => (r2) => ma(f(r2))
8080

8181
/**
8282
* `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types

src/ReaderEither.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export const toUnion: <R, E, A>(fa: ReaderEither<R, E, A>) => Reader<R, E | A> =
230230
* @category combinators
231231
* @since 3.0.0
232232
*/
233-
export const local: <R2, R1>(f: (r2: R2) => R1) => <E, A>(ma: ReaderEither<R1, E, A>) => ReaderEither<R2, E, A> =
233+
export const local: <R1, R2 = R1>(f: (r2: R2) => R1) => <E, A>(ma: ReaderEither<R1, E, A>) => ReaderEither<R2, E, A> =
234234
R.local
235235

236236
/**

src/ReaderIO.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const fromIO: FromIO2<URI>['fromIO'] = /*#__PURE__*/ R.of
5959
* @category combinators
6060
* @since 3.0.0
6161
*/
62-
export const local: <R2, R1>(f: (r2: R2) => R1) => <A>(ma: ReaderIO<R1, A>) => ReaderIO<R2, A> = R.local
62+
export const local: <R1, R2 = R1>(f: (r2: R2) => R1) => <A>(ma: ReaderIO<R1, A>) => ReaderIO<R2, A> = R.local
6363

6464
/**
6565
* Less strict version of [`asksReaderIO`](#asksreaderio).

src/ReaderTask.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export const fromIO: FromIO2<URI>['fromIO'] =
100100
* @category combinators
101101
* @since 3.0.0
102102
*/
103-
export const local: <R2, R1>(f: (r2: R2) => R1) => <A>(ma: ReaderTask<R1, A>) => ReaderTask<R2, A> = R.local
103+
export const local: <R1, R2 = R1>(f: (r2: R2) => R1) => <A>(ma: ReaderTask<R1, A>) => ReaderTask<R2, A> = R.local
104104

105105
/**
106106
* `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types

src/ReaderTaskEither.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ export const chainNullableK: <E>(
369369
* @category combinators
370370
* @since 3.0.0
371371
*/
372-
export const local: <R2, R1>(
372+
export const local: <R1, R2 = R1>(
373373
f: (r2: R2) => R1
374374
) => <E, A>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R2, E, A> = R.local
375375

src/StateReaderTaskEither.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export const fromReaderTaskEither: NaturalTransformation34<RTE.URI, URI> =
248248
* @category combinators
249249
* @since 3.0.0
250250
*/
251-
export const local = <R2, R1>(f: (r2: R2) => R1) => <S, E, A>(
251+
export const local = <R1, R2 = R1>(f: (r2: R2) => R1) => <S, E, A>(
252252
ma: StateReaderTaskEither<S, R1, E, A>
253253
): StateReaderTaskEither<S, R2, E, A> => flow(ma, R.local(f))
254254

0 commit comments

Comments
 (0)