diff --git a/docs/modules/ReaderEither.ts.md b/docs/modules/ReaderEither.ts.md index 72d098f0d..59d9e88fd 100644 --- a/docs/modules/ReaderEither.ts.md +++ b/docs/modules/ReaderEither.ts.md @@ -32,7 +32,9 @@ Added in v2.0.0 - [of](#of) - [combinators](#combinators) - [apFirst](#apfirst) + - [apFirstW](#apfirstw) - [apSecond](#apsecond) + - [apSecondW](#apsecondw) - [asksReaderEither](#asksreadereither) - [asksReaderEitherW](#asksreadereitherw) - [chainEitherK](#chaineitherk) @@ -300,6 +302,20 @@ export declare const apFirst: ( Added in v2.0.0 +## apFirstW + +Less strict version of [`apFirst`](#apfirst) + +**Signature** + +```ts +export declare const apFirstW: ( + second: ReaderEither +) => (first: ReaderEither) => ReaderEither +``` + +Added in v2.12.0 + ## apSecond Combine two effectful actions, keeping only the result of the second. @@ -316,6 +332,20 @@ export declare const apSecond: ( Added in v2.0.0 +## apSecondW + +Less strict version of [`apSecond`](#apsecond) + +**Signature** + +```ts +export declare const apSecondW: ( + second: ReaderEither +) => (first: ReaderEither) => ReaderEither +``` + +Added in v2.12.0 + ## asksReaderEither Effectfully accesses the environment. diff --git a/src/ReaderEither.ts b/src/ReaderEither.ts index 65df1c170..8728cae76 100644 --- a/src/ReaderEither.ts +++ b/src/ReaderEither.ts @@ -596,6 +596,16 @@ export const apFirst = /*#__PURE__*/ apFirst_(Apply) +/** + * Less strict version of [`apFirst`](#apfirst) + * + * @category combinators + * @since 2.12.0 + */ +export const apFirstW: ( + second: ReaderEither +) => (first: ReaderEither) => ReaderEither = apFirst as any + /** * Combine two effectful actions, keeping only the result of the second. * @@ -608,6 +618,16 @@ export const apSecond = /*#__PURE__*/ apSecond_(Apply) +/** + * Less strict version of [`apSecond`](#apsecond) + * + * @category combinators + * @since 2.12.0 + */ +export const apSecondW: ( + second: ReaderEither +) => (first: ReaderEither) => ReaderEither = apSecond as any + /** * @category instances * @since 2.7.0 diff --git a/test/ReaderEither.ts b/test/ReaderEither.ts index 51002c437..e723462dd 100644 --- a/test/ReaderEither.ts +++ b/test/ReaderEither.ts @@ -42,10 +42,22 @@ describe('ReaderEither', () => { U.deepStrictEqual(pipe(_.right('a'), _.apFirst(_.right('b')))({}), E.right('a')) }) + it('apFirstW', () => { + const fa = _.right<{ readonly k: string }, 'Foo', string>('a') + const fb = _.right<{ readonly x: number }, 'Bar', number>(4) + U.deepStrictEqual(pipe(fa, _.apFirstW(fb))({ k: 'v', x: 1 }), E.right('a')) + }) + it('apSecond', () => { U.deepStrictEqual(pipe(_.right('a'), _.apSecond(_.right('b')))({}), E.right('b')) }) + it('apSecondW', () => { + const fa = _.right<{ readonly k: string }, 'Foo', string>('a') + const fb = _.right<{ readonly x: number }, 'Bar', number>(4) + U.deepStrictEqual(pipe(fa, _.apSecondW(fb))({ k: 'v', x: 1 }), E.right(4)) + }) + it('chainFirst', () => { const f = (n: number) => _.right(n * 2) U.deepStrictEqual(pipe(_.right(1), _.chainFirst(f))({}), E.right(1))