diff --git a/docs/modules/Reader.ts.md b/docs/modules/Reader.ts.md index 9d00e7948..baeeade6e 100644 --- a/docs/modules/Reader.ts.md +++ b/docs/modules/Reader.ts.md @@ -442,7 +442,8 @@ 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 function local(f: (r2: R2) => R1): (ma: Reader) => Reader +export declare function local(f: (r2: R2) => R1): (ma: Reader) => Reader ``` **Example** diff --git a/docs/modules/ReaderEither.ts.md b/docs/modules/ReaderEither.ts.md index 7cc4f0743..ae7e594e5 100644 --- a/docs/modules/ReaderEither.ts.md +++ b/docs/modules/ReaderEither.ts.md @@ -661,9 +661,10 @@ 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 + (f: (r2: R2) => R1): (ma: ReaderEither) => ReaderEither +} ``` Added in v2.0.0 diff --git a/docs/modules/ReaderIO.ts.md b/docs/modules/ReaderIO.ts.md index fa51ebe08..f1d1f89d4 100644 --- a/docs/modules/ReaderIO.ts.md +++ b/docs/modules/ReaderIO.ts.md @@ -377,7 +377,10 @@ 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: ReaderIO) => ReaderIO +export declare const local: { + (f: (r2: R2) => R1): (ma: ReaderIO) => ReaderIO + (f: (r2: R2) => R1): (ma: ReaderIO) => ReaderIO +} ``` Added in v2.13.0 diff --git a/docs/modules/ReaderTask.ts.md b/docs/modules/ReaderTask.ts.md index 9b6eb583b..8c958fd3c 100644 --- a/docs/modules/ReaderTask.ts.md +++ b/docs/modules/ReaderTask.ts.md @@ -441,7 +441,10 @@ 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 + (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 2b08d6089..a1ce20d5b 100644 --- a/docs/modules/ReaderTaskEither.ts.md +++ b/docs/modules/ReaderTaskEither.ts.md @@ -1032,9 +1032,10 @@ 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: ReaderTaskEither) => ReaderTaskEither +export declare const local: { + (f: (r2: R2) => R1): (ma: ReaderTaskEither) => ReaderTaskEither + (f: (r2: R2) => R1): (ma: ReaderTaskEither) => ReaderTaskEither +} ``` Added in v2.0.0 diff --git a/docs/modules/StateReaderTaskEither.ts.md b/docs/modules/StateReaderTaskEither.ts.md index 25daa9656..f2f5d7aa6 100644 --- a/docs/modules/StateReaderTaskEither.ts.md +++ b/docs/modules/StateReaderTaskEither.ts.md @@ -903,9 +903,12 @@ Changes the value of the local context during the execution of the action `ma` ( **Signature** ```ts -export declare const local: ( +export declare function local( f: (r2: R2) => R1 -) => (ma: StateReaderTaskEither) => StateReaderTaskEither +): (ma: StateReaderTaskEither) => StateReaderTaskEither +export declare function local( + f: (r2: R2) => R1 +): (ma: StateReaderTaskEither) => StateReaderTaskEither ``` Added in v2.11.0 diff --git a/dtslint/ts3.5/Reader.ts b/dtslint/ts3.5/Reader.ts index 1dc3e3a30..ecbe132c4 100644 --- a/dtslint/ts3.5/Reader.ts +++ b/dtslint/ts3.5/Reader.ts @@ -1,6 +1,8 @@ import * as _ from '../../src/Reader' import { pipe } from '../../src/function' +declare function modifyA(r: R): R + // // local // @@ -21,6 +23,9 @@ pipe( })) ) +// $ExpectType Reader<{ a: string; b: string; }, string> +pipe(_.of<{ a: string; b: string }, string>('a'), _.local(modifyA)) + // // chainW // diff --git a/dtslint/ts3.5/ReaderEither.ts b/dtslint/ts3.5/ReaderEither.ts index 7150d4285..6b31bb5b9 100644 --- a/dtslint/ts3.5/ReaderEither.ts +++ b/dtslint/ts3.5/ReaderEither.ts @@ -3,6 +3,8 @@ import * as R from '../../src/Reader' import * as E from '../../src/Either' import { pipe } from '../../src/function' +declare function modifyA(r: R): R + // // local // @@ -23,6 +25,9 @@ pipe( })) ) +// $ExpectType ReaderEither<{ a: string; b: string; }, number, string> +pipe(_.of<{ a: string; b: string }, number, string>('a'), _.local(modifyA)) + // // getOrElseW // diff --git a/dtslint/ts3.5/ReaderIO.ts b/dtslint/ts3.5/ReaderIO.ts new file mode 100644 index 000000000..1881c120a --- /dev/null +++ b/dtslint/ts3.5/ReaderIO.ts @@ -0,0 +1,27 @@ +import * as _ from '../../src/ReaderIO' +import { pipe } from '../../src/function' + +declare function modifyA(r: R): R + +// +// local +// + +// $ExpectType ReaderIO<{ a: string; }, string> +pipe( + _.of<{ a: string }, string>('a'), + _.local((env) => ({ + a: env.a + })) +) + +// $ExpectType ReaderIO<{ b: string; }, string> +pipe( + _.of<{ a: string }, string>('a'), + _.local((env: { b: string }) => ({ + a: env.b + })) +) + +// $ExpectType ReaderIO<{ a: string; b: string; }, string> +pipe(_.of<{ a: string; b: string }, string>('a'), _.local(modifyA)) diff --git a/dtslint/ts3.5/ReaderTask.ts b/dtslint/ts3.5/ReaderTask.ts index 3d89bd438..2994ca990 100644 --- a/dtslint/ts3.5/ReaderTask.ts +++ b/dtslint/ts3.5/ReaderTask.ts @@ -1,6 +1,8 @@ import * as _ from '../../src/ReaderTask' import { pipe } from '../../src/function' +declare function modifyA(r: R): R + // // local // @@ -21,6 +23,9 @@ pipe( })) ) +// $ExpectType ReaderTask<{ a: string; b: string; }, string> +pipe(_.of<{ a: string; b: string }, string>('a'), _.local(modifyA)) + // // Do // diff --git a/dtslint/ts3.5/ReaderTaskEither.ts b/dtslint/ts3.5/ReaderTaskEither.ts index 1b2ff051d..db7589f96 100644 --- a/dtslint/ts3.5/ReaderTaskEither.ts +++ b/dtslint/ts3.5/ReaderTaskEither.ts @@ -5,6 +5,8 @@ import * as TE from '../../src/TaskEither' import * as IOE from '../../src/IOEither' import { pipe } from '../../src/function' +declare function modifyA(r: R): R + // // local // @@ -25,6 +27,9 @@ pipe( })) ) +// $ExpectType ReaderTaskEither<{ a: string; b: string; }, number, string> +pipe(_.of<{ a: string; b: string }, number, string>('a'), _.local(modifyA)) + // // getOrElseW // diff --git a/dtslint/ts3.5/StateReaderTaskEither.ts b/dtslint/ts3.5/StateReaderTaskEither.ts index 8fb0c5534..51ed3a5f3 100644 --- a/dtslint/ts3.5/StateReaderTaskEither.ts +++ b/dtslint/ts3.5/StateReaderTaskEither.ts @@ -5,6 +5,8 @@ import * as RTE from '../../src/ReaderTaskEither' import * as IOE from '../../src/IOEither' import { pipe } from '../../src/function' +declare function modifyA(r: R): R + // // local // @@ -25,6 +27,9 @@ pipe( })) ) +// $ExpectType StateReaderTaskEither +pipe(_.of('a'), _.local(modifyA)) + // // chainW // diff --git a/src/Reader.ts b/src/Reader.ts index 44e88fcf0..cc23fb92a 100644 --- a/src/Reader.ts +++ b/src/Reader.ts @@ -123,8 +123,11 @@ 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) => - ma(f(r2)) +export function local(f: (r2: R2) => R1): (ma: Reader) => Reader +export function local(f: (r2: R2) => R1): (ma: Reader) => Reader +export function local(f: (r2: R2) => R1): (ma: Reader) => Reader { + return (ma) => (r2) => ma(f(r2)) +} /** * Less strict version of [`asksReader`](#asksreader). diff --git a/src/ReaderEither.ts b/src/ReaderEither.ts index 7779fc5af..3b21a2ea2 100644 --- a/src/ReaderEither.ts +++ b/src/ReaderEither.ts @@ -217,8 +217,10 @@ export const toUnion: (fa: ReaderEither) => Reader = * @category combinators * @since 2.0.0 */ -export const local: (f: (r2: R2) => R1) => (ma: ReaderEither) => ReaderEither = - R.local +export const local: { + (f: (r2: R2) => R1): (ma: ReaderEither) => ReaderEither + (f: (r2: R2) => R1): (ma: ReaderEither) => ReaderEither +} = R.local /** * Less strict version of [`asksReaderEither`](#asksreadereither). diff --git a/src/ReaderIO.ts b/src/ReaderIO.ts index 3365d1598..1b322c050 100644 --- a/src/ReaderIO.ts +++ b/src/ReaderIO.ts @@ -64,7 +64,10 @@ export const fromIO: FromIO2['fromIO'] = * @category combinators * @since 2.13.0 */ -export const local: (f: (r2: R2) => R1) => (ma: ReaderIO) => ReaderIO = R.local +export const local: { + (f: (r2: R2) => R1): (ma: ReaderIO) => ReaderIO + (f: (r2: R2) => R1): (ma: ReaderIO) => ReaderIO +} = R.local /** * Less strict version of [`asksReaderIO`](#asksreaderio). diff --git a/src/ReaderTask.ts b/src/ReaderTask.ts index ad3988837..c79aea3b8 100644 --- a/src/ReaderTask.ts +++ b/src/ReaderTask.ts @@ -86,7 +86,10 @@ 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 + (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 990e31916..0eac40a4e 100644 --- a/src/ReaderTaskEither.ts +++ b/src/ReaderTaskEither.ts @@ -350,9 +350,10 @@ export const chainNullableK: ( * @category combinators * @since 2.0.0 */ -export const local: ( - f: (r2: R2) => R1 -) => (ma: ReaderTaskEither) => ReaderTaskEither = R.local +export const local: { + (f: (r2: R2) => R1): (ma: ReaderTaskEither) => ReaderTaskEither + (f: (r2: R2) => R1): (ma: ReaderTaskEither) => ReaderTaskEither +} = R.local /** * Less strict version of [`asksReaderTaskEither`](#asksreadertaskeither). diff --git a/src/StateReaderTaskEither.ts b/src/StateReaderTaskEither.ts index 5e9f1c4ca..eff74ed8b 100644 --- a/src/StateReaderTaskEither.ts +++ b/src/StateReaderTaskEither.ts @@ -234,9 +234,17 @@ export const fromReaderTaskEither: NaturalTransformation34 = /*#__ * @category combinators * @since 2.11.0 */ -export const local = (f: (r2: R2) => R1) => ( - ma: StateReaderTaskEither -): StateReaderTaskEither => flow(ma, R.local(f)) +export function local( + f: (r2: R2) => R1 +): (ma: StateReaderTaskEither) => StateReaderTaskEither +export function local( + f: (r2: R2) => R1 +): (ma: StateReaderTaskEither) => StateReaderTaskEither +export function local( + f: (r2: R2) => R1 +): (ma: StateReaderTaskEither) => StateReaderTaskEither { + return (ma) => flow(ma, R.local(f)) +} /** * Less strict version of [`asksStateReaderTaskEither`](#asksstatereadertaskeither).