Skip to content

Commit

Permalink
Use overloading to make it backwards compatible, and support ReaderIO
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Sep 8, 2022
1 parent 22b1939 commit aed3659
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 23 deletions.
3 changes: 2 additions & 1 deletion docs/modules/Reader.ts.md
Expand Up @@ -442,7 +442,8 @@ Changes the value of the local context during the execution of the action `ma` (
**Signature**

```ts
export declare const local: <R1, R2 = R1>(f: (r2: R2) => R1) => <A>(ma: Reader<R1, A>) => Reader<R2, A>
export declare function local<R1, R2 = R1>(f: (r2: R2) => R1): <A>(ma: Reader<R1, A>) => Reader<R2, A>
export declare function local<R2, R1>(f: (r2: R2) => R1): <A>(ma: Reader<R1, A>) => Reader<R2, A>
```

**Example**
Expand Down
7 changes: 4 additions & 3 deletions docs/modules/ReaderEither.ts.md
Expand Up @@ -661,9 +661,10 @@ Changes the value of the local context during the execution of the action `ma` (
**Signature**

```ts
export declare const local: <R1, R2 = R1>(
f: (r2: R2) => R1
) => <E, A>(ma: ReaderEither<R1, E, A>) => ReaderEither<R2, E, A>
export declare const local: {
<R1, R2 = R1>(f: (r2: R2) => R1): <E, A>(ma: ReaderEither<R1, E, A>) => ReaderEither<R2, E, A>
<R2, R1>(f: (r2: R2) => R1): <E, A>(ma: ReaderEither<R1, E, A>) => ReaderEither<R2, E, A>
}
```

Added in v2.0.0
Expand Down
5 changes: 4 additions & 1 deletion docs/modules/ReaderIO.ts.md
Expand Up @@ -377,7 +377,10 @@ Changes the value of the local context during the execution of the action `ma` (
**Signature**

```ts
export declare const local: <R2, R1>(f: (r2: R2) => R1) => <A>(ma: ReaderIO<R1, A>) => ReaderIO<R2, A>
export declare const local: {
<R1, R2 = R1>(f: (r2: R2) => R1): <A>(ma: ReaderIO<R1, A>) => ReaderIO<R2, A>
<R2, R1>(f: (r2: R2) => R1): <A>(ma: ReaderIO<R1, A>) => ReaderIO<R2, A>
}
```

Added in v2.13.0
Expand Down
5 changes: 4 additions & 1 deletion docs/modules/ReaderTask.ts.md
Expand Up @@ -441,7 +441,10 @@ Changes the value of the local context during the execution of the action `ma` (
**Signature**

```ts
export declare const local: <R1, R2 = R1>(f: (r2: R2) => R1) => <A>(ma: ReaderTask<R1, A>) => ReaderTask<R2, A>
export declare const local: {
<R1, R2 = R1>(f: (r2: R2) => R1): <A>(ma: ReaderTask<R1, A>) => ReaderTask<R2, A>
<R2, R1>(f: (r2: R2) => R1): <A>(ma: ReaderTask<R1, A>) => ReaderTask<R2, A>
}
```

Added in v2.3.0
Expand Down
7 changes: 4 additions & 3 deletions docs/modules/ReaderTaskEither.ts.md
Expand Up @@ -1032,9 +1032,10 @@ Changes the value of the local context during the execution of the action `ma` (
**Signature**

```ts
export declare const local: <R1, R2 = R1>(
f: (r2: R2) => R1
) => <E, A>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R2, E, A>
export declare const local: {
<R1, R2 = R1>(f: (r2: R2) => R1): <E, A>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R2, E, A>
<R2, R1>(f: (r2: R2) => R1): <E, A>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R2, E, A>
}
```

Added in v2.0.0
Expand Down
7 changes: 5 additions & 2 deletions docs/modules/StateReaderTaskEither.ts.md
Expand Up @@ -903,9 +903,12 @@ Changes the value of the local context during the execution of the action `ma` (
**Signature**

```ts
export declare const local: <R1, R2 = R1>(
export declare function local<R1, R2 = R1>(
f: (r2: R2) => R1
) => <S, E, A>(ma: StateReaderTaskEither<S, R1, E, A>) => StateReaderTaskEither<S, R2, E, A>
): <S, E, A>(ma: StateReaderTaskEither<S, R1, E, A>) => StateReaderTaskEither<S, R2, E, A>
export declare function local<R2, R1>(
f: (r2: R2) => R1
): <S, E, A>(ma: StateReaderTaskEither<S, R1, E, A>) => StateReaderTaskEither<S, R2, E, A>
```

Added in v2.11.0
Expand Down
5 changes: 5 additions & 0 deletions dtslint/ts3.5/Reader.ts
@@ -1,6 +1,8 @@
import * as _ from '../../src/Reader'
import { pipe } from '../../src/function'

declare function modifyA<R extends { a: string }>(r: R): R

//
// local
//
Expand All @@ -21,6 +23,9 @@ pipe(
}))
)

// $ExpectType Reader<{ a: string; b: string; }, string>
pipe(_.of<{ a: string; b: string }, string>('a'), _.local(modifyA))

//
// chainW
//
Expand Down
5 changes: 5 additions & 0 deletions dtslint/ts3.5/ReaderEither.ts
Expand Up @@ -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 extends { a: string }>(r: R): R

//
// local
//
Expand All @@ -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
//
Expand Down
27 changes: 27 additions & 0 deletions dtslint/ts3.5/ReaderIO.ts
@@ -0,0 +1,27 @@
import * as _ from '../../src/ReaderIO'
import { pipe } from '../../src/function'

declare function modifyA<R extends { a: string }>(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))
5 changes: 5 additions & 0 deletions dtslint/ts3.5/ReaderTask.ts
@@ -1,6 +1,8 @@
import * as _ from '../../src/ReaderTask'
import { pipe } from '../../src/function'

declare function modifyA<R extends { a: string }>(r: R): R

//
// local
//
Expand All @@ -21,6 +23,9 @@ pipe(
}))
)

// $ExpectType ReaderTask<{ a: string; b: string; }, string>
pipe(_.of<{ a: string; b: string }, string>('a'), _.local(modifyA))

//
// Do
//
Expand Down
5 changes: 5 additions & 0 deletions dtslint/ts3.5/ReaderTaskEither.ts
Expand Up @@ -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 extends { a: string }>(r: R): R

//
// local
//
Expand All @@ -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
//
Expand Down
5 changes: 5 additions & 0 deletions dtslint/ts3.5/StateReaderTaskEither.ts
Expand Up @@ -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 extends { a: string }>(r: R): R

//
// local
//
Expand All @@ -25,6 +27,9 @@ pipe(
}))
)

// $ExpectType StateReaderTaskEither<boolean, { a: string; b: string; }, number, string>
pipe(_.of<boolean, { a: string; b: string }, number, string>('a'), _.local(modifyA))

//
// chainW
//
Expand Down
7 changes: 5 additions & 2 deletions src/Reader.ts
Expand Up @@ -123,8 +123,11 @@ export const asks: <R, A>(f: (r: R) => A) => Reader<R, A> = identity
* @category combinators
* @since 2.0.0
*/
export const local: <R1, R2 = R1>(f: (r2: R2) => R1) => <A>(ma: Reader<R1, A>) => Reader<R2, A> = (f) => (ma) => (r2) =>
ma(f(r2))
export function local<R1, R2 = R1>(f: (r2: R2) => R1): <A>(ma: Reader<R1, A>) => Reader<R2, A>
export function local<R2, R1>(f: (r2: R2) => R1): <A>(ma: Reader<R1, A>) => Reader<R2, A>
export function local<R2, R1>(f: (r2: R2) => R1): <A>(ma: Reader<R1, A>) => Reader<R2, A> {
return (ma) => (r2) => ma(f(r2))
}

/**
* Less strict version of [`asksReader`](#asksreader).
Expand Down
6 changes: 4 additions & 2 deletions src/ReaderEither.ts
Expand Up @@ -217,8 +217,10 @@ export const toUnion: <R, E, A>(fa: ReaderEither<R, E, A>) => Reader<R, E | A> =
* @category combinators
* @since 2.0.0
*/
export const local: <R1, R2 = R1>(f: (r2: R2) => R1) => <E, A>(ma: ReaderEither<R1, E, A>) => ReaderEither<R2, E, A> =
R.local
export const local: {
<R1, R2 = R1>(f: (r2: R2) => R1): <E, A>(ma: ReaderEither<R1, E, A>) => ReaderEither<R2, E, A>
<R2, R1>(f: (r2: R2) => R1): <E, A>(ma: ReaderEither<R1, E, A>) => ReaderEither<R2, E, A>
} = R.local

/**
* Less strict version of [`asksReaderEither`](#asksreadereither).
Expand Down
5 changes: 4 additions & 1 deletion src/ReaderIO.ts
Expand Up @@ -64,7 +64,10 @@ export const fromIO: FromIO2<URI>['fromIO'] =
* @category combinators
* @since 2.13.0
*/
export const local: <R2, R1>(f: (r2: R2) => R1) => <A>(ma: ReaderIO<R1, A>) => ReaderIO<R2, A> = R.local
export const local: {
<R1, R2 = R1>(f: (r2: R2) => R1): <A>(ma: ReaderIO<R1, A>) => ReaderIO<R2, A>
<R2, R1>(f: (r2: R2) => R1): <A>(ma: ReaderIO<R1, A>) => ReaderIO<R2, A>
} = R.local

/**
* Less strict version of [`asksReaderIO`](#asksreaderio).
Expand Down
5 changes: 4 additions & 1 deletion src/ReaderTask.ts
Expand Up @@ -86,7 +86,10 @@ export const fromIO: FromIO2<URI>['fromIO'] = /*#__PURE__*/ flow(T.fromIO, fromT
* @category combinators
* @since 2.3.0
*/
export const local: <R1, R2 = R1>(f: (r2: R2) => R1) => <A>(ma: ReaderTask<R1, A>) => ReaderTask<R2, A> = R.local
export const local: {
<R1, R2 = R1>(f: (r2: R2) => R1): <A>(ma: ReaderTask<R1, A>) => ReaderTask<R2, A>
<R2, R1>(f: (r2: R2) => R1): <A>(ma: ReaderTask<R1, A>) => ReaderTask<R2, A>
} = R.local

/**
* Less strict version of [`asksReaderTask`](#asksreadertask).
Expand Down
7 changes: 4 additions & 3 deletions src/ReaderTaskEither.ts
Expand Up @@ -350,9 +350,10 @@ export const chainNullableK: <E>(
* @category combinators
* @since 2.0.0
*/
export const local: <R1, R2 = R1>(
f: (r2: R2) => R1
) => <E, A>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R2, E, A> = R.local
export const local: {
<R1, R2 = R1>(f: (r2: R2) => R1): <E, A>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R2, E, A>
<R2, R1>(f: (r2: R2) => R1): <E, A>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R2, E, A>
} = R.local

/**
* Less strict version of [`asksReaderTaskEither`](#asksreadertaskeither).
Expand Down
14 changes: 11 additions & 3 deletions src/StateReaderTaskEither.ts
Expand Up @@ -234,9 +234,17 @@ export const fromReaderTaskEither: NaturalTransformation34<RTE.URI, URI> = /*#__
* @category combinators
* @since 2.11.0
*/
export const local = <R1, R2 = R1>(f: (r2: R2) => R1) => <S, E, A>(
ma: StateReaderTaskEither<S, R1, E, A>
): StateReaderTaskEither<S, R2, E, A> => flow(ma, R.local(f))
export function local<R1, R2 = R1>(
f: (r2: R2) => R1
): <S, E, A>(ma: StateReaderTaskEither<S, R1, E, A>) => StateReaderTaskEither<S, R2, E, A>
export function local<R2, R1>(
f: (r2: R2) => R1
): <S, E, A>(ma: StateReaderTaskEither<S, R1, E, A>) => StateReaderTaskEither<S, R2, E, A>
export function local<R2, R1>(
f: (r2: R2) => R1
): <S, E, A>(ma: StateReaderTaskEither<S, R1, E, A>) => StateReaderTaskEither<S, R2, E, A> {
return (ma) => flow(ma, R.local(f))
}

/**
* Less strict version of [`asksStateReaderTaskEither`](#asksstatereadertaskeither).
Expand Down

0 comments on commit aed3659

Please sign in to comment.