diff --git a/docs/modules/Reader.ts.md b/docs/modules/Reader.ts.md index c4d8c690ee..9d00e7948f 100644 --- a/docs/modules/Reader.ts.md +++ b/docs/modules/Reader.ts.md @@ -442,7 +442,7 @@ Changes the value of the local context during the execution of the action `ma` ( **Signature** ```ts -export declare const local: (f: (r2: R2) => R1) => (ma: Reader) => Reader +export declare const local: (f: (r2: R2) => R1) => (ma: Reader) => Reader ``` **Example** diff --git a/docs/modules/ReaderEither.ts.md b/docs/modules/ReaderEither.ts.md index a727db0f9d..7cc4f07434 100644 --- a/docs/modules/ReaderEither.ts.md +++ b/docs/modules/ReaderEither.ts.md @@ -661,7 +661,9 @@ Changes the value of the local context during the execution of the action `ma` ( **Signature** ```ts -export declare const local: (f: (r2: R2) => R1) => (ma: ReaderEither) => ReaderEither +export declare const local: ( + f: (r2: R2) => R1 +) => (ma: ReaderEither) => ReaderEither ``` Added in v2.0.0 diff --git a/docs/modules/ReaderTask.ts.md b/docs/modules/ReaderTask.ts.md index e136ea5756..9b6eb583bc 100644 --- a/docs/modules/ReaderTask.ts.md +++ b/docs/modules/ReaderTask.ts.md @@ -441,7 +441,7 @@ Changes the value of the local context during the execution of the action `ma` ( **Signature** ```ts -export declare const local: (f: (r2: R2) => R1) => (ma: ReaderTask) => ReaderTask +export declare const local: (f: (r2: R2) => R1) => (ma: ReaderTask) => ReaderTask ``` Added in v2.3.0 diff --git a/docs/modules/ReaderTaskEither.ts.md b/docs/modules/ReaderTaskEither.ts.md index 8ee8486229..2b08d60895 100644 --- a/docs/modules/ReaderTaskEither.ts.md +++ b/docs/modules/ReaderTaskEither.ts.md @@ -1032,7 +1032,7 @@ Changes the value of the local context during the execution of the action `ma` ( **Signature** ```ts -export declare const local: ( +export declare const local: ( f: (r2: R2) => R1 ) => (ma: ReaderTaskEither) => ReaderTaskEither ``` diff --git a/docs/modules/StateReaderTaskEither.ts.md b/docs/modules/StateReaderTaskEither.ts.md index 8d7cf0813e..25daa96565 100644 --- a/docs/modules/StateReaderTaskEither.ts.md +++ b/docs/modules/StateReaderTaskEither.ts.md @@ -903,7 +903,7 @@ Changes the value of the local context during the execution of the action `ma` ( **Signature** ```ts -export declare const local: ( +export declare const local: ( f: (r2: R2) => R1 ) => (ma: StateReaderTaskEither) => StateReaderTaskEither ``` diff --git a/dtslint/ts3.5/Reader.ts b/dtslint/ts3.5/Reader.ts index fb3081eb9c..1dc3e3a300 100644 --- a/dtslint/ts3.5/Reader.ts +++ b/dtslint/ts3.5/Reader.ts @@ -1,6 +1,26 @@ import * as _ from '../../src/Reader' import { pipe } from '../../src/function' +// +// local +// + +// $ExpectType Reader<{ a: string; }, string> +pipe( + _.of<{ a: string }, string>('a'), + _.local((env) => ({ + a: env.a + })) +) + +// $ExpectType Reader<{ b: string; }, string> +pipe( + _.of<{ a: string }, string>('a'), + _.local((env: { b: string }) => ({ + a: env.b + })) +) + // // chainW // diff --git a/dtslint/ts3.5/ReaderEither.ts b/dtslint/ts3.5/ReaderEither.ts index 459e2d955c..7150d4285c 100644 --- a/dtslint/ts3.5/ReaderEither.ts +++ b/dtslint/ts3.5/ReaderEither.ts @@ -3,6 +3,26 @@ import * as R from '../../src/Reader' import * as E from '../../src/Either' import { pipe } from '../../src/function' +// +// local +// + +// $ExpectType ReaderEither<{ a: string; }, number, string> +pipe( + _.of<{ a: string }, number, string>('a'), + _.local((env) => ({ + a: env.a + })) +) + +// $ExpectType ReaderEither<{ b: string; }, number, string> +pipe( + _.of<{ a: string }, number, string>('a'), + _.local((env: { b: string }) => ({ + a: env.b + })) +) + // // getOrElseW // diff --git a/dtslint/ts3.5/ReaderTask.ts b/dtslint/ts3.5/ReaderTask.ts index ce12aa9dd4..3d89bd4383 100644 --- a/dtslint/ts3.5/ReaderTask.ts +++ b/dtslint/ts3.5/ReaderTask.ts @@ -1,6 +1,26 @@ import * as _ from '../../src/ReaderTask' import { pipe } from '../../src/function' +// +// local +// + +// $ExpectType ReaderTask<{ a: string; }, string> +pipe( + _.of<{ a: string }, string>('a'), + _.local((env) => ({ + a: env.a + })) +) + +// $ExpectType ReaderTask<{ b: string; }, string> +pipe( + _.of<{ a: string }, string>('a'), + _.local((env: { b: string }) => ({ + a: env.b + })) +) + // // Do // diff --git a/dtslint/ts3.5/ReaderTaskEither.ts b/dtslint/ts3.5/ReaderTaskEither.ts index a95b22573d..1b2ff051db 100644 --- a/dtslint/ts3.5/ReaderTaskEither.ts +++ b/dtslint/ts3.5/ReaderTaskEither.ts @@ -5,6 +5,26 @@ import * as TE from '../../src/TaskEither' import * as IOE from '../../src/IOEither' import { pipe } from '../../src/function' +// +// local +// + +// $ExpectType ReaderTaskEither<{ a: string; }, number, string> +pipe( + _.of<{ a: string }, number, string>('a'), + _.local((env) => ({ + a: env.a + })) +) + +// $ExpectType ReaderTaskEither<{ b: string; }, number, string> +pipe( + _.of<{ a: string }, number, string>('a'), + _.local((env: { b: string }) => ({ + a: env.b + })) +) + // // getOrElseW // diff --git a/dtslint/ts3.5/StateReaderTaskEither.ts b/dtslint/ts3.5/StateReaderTaskEither.ts index 2583a8fc24..8fb0c55341 100644 --- a/dtslint/ts3.5/StateReaderTaskEither.ts +++ b/dtslint/ts3.5/StateReaderTaskEither.ts @@ -5,6 +5,26 @@ import * as RTE from '../../src/ReaderTaskEither' import * as IOE from '../../src/IOEither' import { pipe } from '../../src/function' +// +// local +// + +// $ExpectType StateReaderTaskEither +pipe( + _.of('a'), + _.local((env) => ({ + a: env.a + })) +) + +// $ExpectType StateReaderTaskEither +pipe( + _.of('a'), + _.local((env: { b: string }) => ({ + a: env.b + })) +) + // // chainW // diff --git a/src/Reader.ts b/src/Reader.ts index 486fe1494e..44e88fcf04 100644 --- a/src/Reader.ts +++ b/src/Reader.ts @@ -123,7 +123,7 @@ export const asks: (f: (r: R) => A) => Reader = identity * @category combinators * @since 2.0.0 */ -export const local: (f: (r2: R2) => R1) => (ma: Reader) => Reader = (f) => (ma) => (r2) => +export const local: (f: (r2: R2) => R1) => (ma: Reader) => Reader = (f) => (ma) => (r2) => ma(f(r2)) /** diff --git a/src/ReaderEither.ts b/src/ReaderEither.ts index 5274493394..7779fc5af1 100644 --- a/src/ReaderEither.ts +++ b/src/ReaderEither.ts @@ -217,7 +217,7 @@ export const toUnion: (fa: ReaderEither) => Reader = * @category combinators * @since 2.0.0 */ -export const local: (f: (r2: R2) => R1) => (ma: ReaderEither) => ReaderEither = +export const local: (f: (r2: R2) => R1) => (ma: ReaderEither) => ReaderEither = R.local /** diff --git a/src/ReaderTask.ts b/src/ReaderTask.ts index 7e2cba52f1..ad39888375 100644 --- a/src/ReaderTask.ts +++ b/src/ReaderTask.ts @@ -86,7 +86,7 @@ export const fromIO: FromIO2['fromIO'] = /*#__PURE__*/ flow(T.fromIO, fromT * @category combinators * @since 2.3.0 */ -export const local: (f: (r2: R2) => R1) => (ma: ReaderTask) => ReaderTask = R.local +export const local: (f: (r2: R2) => R1) => (ma: ReaderTask) => ReaderTask = R.local /** * Less strict version of [`asksReaderTask`](#asksreadertask). diff --git a/src/ReaderTaskEither.ts b/src/ReaderTaskEither.ts index c3659b0063..990e319164 100644 --- a/src/ReaderTaskEither.ts +++ b/src/ReaderTaskEither.ts @@ -350,7 +350,7 @@ export const chainNullableK: ( * @category combinators * @since 2.0.0 */ -export const local: ( +export const local: ( f: (r2: R2) => R1 ) => (ma: ReaderTaskEither) => ReaderTaskEither = R.local diff --git a/src/StateReaderTaskEither.ts b/src/StateReaderTaskEither.ts index 79957a436f..5e9f1c4ca7 100644 --- a/src/StateReaderTaskEither.ts +++ b/src/StateReaderTaskEither.ts @@ -234,7 +234,7 @@ export const fromReaderTaskEither: NaturalTransformation34 = /*#__ * @category combinators * @since 2.11.0 */ -export const local = (f: (r2: R2) => R1) => ( +export const local = (f: (r2: R2) => R1) => ( ma: StateReaderTaskEither ): StateReaderTaskEither => flow(ma, R.local(f))