diff --git a/docs/modules/ReaderTaskEither.ts.md b/docs/modules/ReaderTaskEither.ts.md index a245274a96..42c1c24470 100644 --- a/docs/modules/ReaderTaskEither.ts.md +++ b/docs/modules/ReaderTaskEither.ts.md @@ -168,11 +168,15 @@ Added in v2.0.0 - [utils](#utils) - [ApT](#apt) - [ap](#ap) + - [apEitherSK](#apeithersk) + - [apEitherSKW](#apeitherskw) - [apFirst](#apfirst) - [apFirstW](#apfirstw) - [apSecond](#apsecond) - [apSecondW](#apsecondw) - [apW](#apw) + - [bindEitherK](#bindeitherk) + - [bindEitherKW](#bindeitherkw) - [bracket](#bracket) - [bracketW](#bracketw) - [local](#local) @@ -2025,6 +2029,36 @@ export declare const ap: ( Added in v2.0.0 +## apEitherSK + +**Signature** + +```ts +export declare const apEitherSK: ( + name: Exclude, + f: E.Either +) => ( + fa: ReaderTaskEither +) => ReaderTaskEither +``` + +Added in v2.13.0 + +## apEitherSKW + +**Signature** + +```ts +export declare const apEitherSKW: ( + name: Exclude, + f: E.Either +) => ( + fa: ReaderTaskEither +) => ReaderTaskEither +``` + +Added in v2.13.0 + ## apFirst Combine two effectful actions, keeping only the result of the first. @@ -2101,6 +2135,36 @@ export declare const apW: ( Added in v2.8.0 +## bindEitherK + +**Signature** + +```ts +export declare const bindEitherK: ( + name: Exclude, + f: (a: A) => E.Either +) => ( + ma: ReaderTaskEither +) => ReaderTaskEither +``` + +Added in v2.13.0 + +## bindEitherKW + +**Signature** + +```ts +export declare const bindEitherKW: ( + name: Exclude, + f: (a: A) => E.Either +) => ( + fa: ReaderTaskEither +) => ReaderTaskEither +``` + +Added in v2.13.0 + ## bracket Make sure that a resource is cleaned up in the event of an exception (\*). The release action is called regardless of diff --git a/src/ReaderTaskEither.ts b/src/ReaderTaskEither.ts index 0469f39a91..a51aa49a32 100644 --- a/src/ReaderTaskEither.ts +++ b/src/ReaderTaskEither.ts @@ -1483,6 +1483,22 @@ export const bindW: ( fa: ReaderTaskEither ) => ReaderTaskEither = bind as any +/** + * @since 2.13.0 + */ +export const bindEitherK = (name: Exclude, f: (a: A) => Either) => + bind(name, (a) => fromEither(f(a))) + +/** + * @since 2.13.0 + */ +export const bindEitherKW: ( + name: Exclude, + f: (a: A) => Either +) => ( + fa: ReaderTaskEither +) => ReaderTaskEither = bindEitherK as any + /** * @category do notation * @since 2.8.0 @@ -1504,6 +1520,22 @@ export const apSW: ( fa: ReaderTaskEither ) => ReaderTaskEither = apS as any +/** + * @since 2.13.0 + */ +export const apEitherSK = (name: Exclude, f: Either) => + apS(name, fromEither(f)) + +/** + * @since 2.13.0 + */ +export const apEitherSKW: ( + name: Exclude, + f: Either +) => ( + fa: ReaderTaskEither +) => ReaderTaskEither = apEitherSK as any + /** * @since 2.11.0 */ diff --git a/test/ReaderTaskEither.ts b/test/ReaderTaskEither.ts index 9e9907148e..4efb2acc48 100644 --- a/test/ReaderTaskEither.ts +++ b/test/ReaderTaskEither.ts @@ -539,6 +539,18 @@ describe('ReaderTaskEither', () => { ) }) + it('bindEitherK', async () => { + U.deepStrictEqual( + await pipe( + _.right(1), + _.bindTo('a'), + _.bindEitherK('b', () => E.right('b')), + _.bindEitherKW('c', () => E.right('c')) + )(undefined)(), + E.right({ a: 1, b: 'b', c: 'c' }) + ) + }) + it('apS', async () => { U.deepStrictEqual( await pipe(_.right(1), _.bindTo('a'), _.apS('b', _.right('b')))(undefined)(), @@ -546,6 +558,18 @@ describe('ReaderTaskEither', () => { ) }) + it('apEitherSK', async () => { + U.deepStrictEqual( + await pipe( + _.right(1), + _.bindTo('a'), + _.apEitherSK('b', E.right('b')), + _.apEitherSKW('c', E.right('c')) + )(undefined)(), + E.right({ a: 1, b: 'b', c: 'c' }) + ) + }) + describe('array utils', () => { const input: ReadonlyNonEmptyArray = ['a', 'b']