Skip to content

Commit

Permalink
Allow Reader's local to infer the environment type
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Sep 2, 2022
1 parent eb83cf8 commit 22b1939
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/modules/Reader.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ 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: Reader<R1, A>) => Reader<R2, A>
export declare const local: <R1, R2 = R1>(f: (r2: R2) => R1) => <A>(ma: Reader<R1, A>) => Reader<R2, A>
```

**Example**
Expand Down
4 changes: 3 additions & 1 deletion docs/modules/ReaderEither.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,9 @@ 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) => <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>
```

Added in v2.0.0
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ReaderTask.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ 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: 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>
```

Added in v2.3.0
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ReaderTaskEither.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ Changes the value of the local context during the execution of the action `ma` (
**Signature**

```ts
export declare const local: <R2, R1>(
export declare const local: <R1, R2 = R1>(
f: (r2: R2) => R1
) => <E, A>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R2, E, A>
```
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/StateReaderTaskEither.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ Changes the value of the local context during the execution of the action `ma` (
**Signature**

```ts
export declare const local: <R2, R1>(
export declare const local: <R1, R2 = R1>(
f: (r2: R2) => R1
) => <S, E, A>(ma: StateReaderTaskEither<S, R1, E, A>) => StateReaderTaskEither<S, R2, E, A>
```
Expand Down
20 changes: 20 additions & 0 deletions dtslint/ts3.5/Reader.ts
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down
20 changes: 20 additions & 0 deletions dtslint/ts3.5/ReaderEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
20 changes: 20 additions & 0 deletions dtslint/ts3.5/ReaderTask.ts
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down
20 changes: 20 additions & 0 deletions dtslint/ts3.5/ReaderTaskEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
20 changes: 20 additions & 0 deletions dtslint/ts3.5/StateReaderTaskEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ import * as RTE from '../../src/ReaderTaskEither'
import * as IOE from '../../src/IOEither'
import { pipe } from '../../src/function'

//
// local
//

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

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

//
// chainW
//
Expand Down
2 changes: 1 addition & 1 deletion src/Reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const asks: <R, A>(f: (r: R) => A) => Reader<R, A> = identity
* @category combinators
* @since 2.0.0
*/
export const local: <R2, R1>(f: (r2: R2) => R1) => <A>(ma: Reader<R1, A>) => Reader<R2, A> = (f) => (ma) => (r2) =>
export const local: <R1, R2 = R1>(f: (r2: R2) => R1) => <A>(ma: Reader<R1, A>) => Reader<R2, A> = (f) => (ma) => (r2) =>
ma(f(r2))

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ReaderEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export const toUnion: <R, E, A>(fa: ReaderEither<R, E, A>) => Reader<R, E | A> =
* @category combinators
* @since 2.0.0
*/
export const local: <R2, R1>(f: (r2: R2) => R1) => <E, A>(ma: ReaderEither<R1, E, A>) => ReaderEither<R2, E, A> =
export const local: <R1, R2 = R1>(f: (r2: R2) => R1) => <E, A>(ma: ReaderEither<R1, E, A>) => ReaderEither<R2, E, A> =
R.local

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ReaderTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const fromIO: FromIO2<URI>['fromIO'] = /*#__PURE__*/ flow(T.fromIO, fromT
* @category combinators
* @since 2.3.0
*/
export const local: <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> = R.local

/**
* Less strict version of [`asksReaderTask`](#asksreadertask).
Expand Down
2 changes: 1 addition & 1 deletion src/ReaderTaskEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export const chainNullableK: <E>(
* @category combinators
* @since 2.0.0
*/
export const local: <R2, R1>(
export const local: <R1, R2 = R1>(
f: (r2: R2) => R1
) => <E, A>(ma: ReaderTaskEither<R1, E, A>) => ReaderTaskEither<R2, E, A> = R.local

Expand Down
2 changes: 1 addition & 1 deletion src/StateReaderTaskEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export const fromReaderTaskEither: NaturalTransformation34<RTE.URI, URI> = /*#__
* @category combinators
* @since 2.11.0
*/
export const local = <R2, R1>(f: (r2: R2) => R1) => <S, E, A>(
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))

Expand Down

0 comments on commit 22b1939

Please sign in to comment.