Skip to content

Commit

Permalink
ReaderTaskEither: add apFirstW and apSecondW
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisFrezzato committed Aug 22, 2021
1 parent 21e03f1 commit 27d9a10
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/modules/ReaderTaskEither.ts.md
Expand Up @@ -32,7 +32,9 @@ Added in v2.0.0
- [of](#of)
- [combinators](#combinators)
- [apFirst](#apfirst)
- [apFirstW](#apfirstw)
- [apSecond](#apsecond)
- [apSecondW](#apsecondw)
- [asksReaderTaskEither](#asksreadertaskeither)
- [asksReaderTaskEitherW](#asksreadertaskeitherw)
- [chainEitherK](#chaineitherk)
Expand Down Expand Up @@ -351,6 +353,20 @@ export declare const apFirst: <R, E, B>(

Added in v2.0.0

## apFirstW

Less strict version of [`apFirst`](#apfirst).

**Signature**

```ts
export declare const apFirstW: <R2, E2, A, B>(
second: ReaderTaskEither<R2, E2, B>
) => <R1, E1>(first: ReaderTaskEither<R1, E1, A>) => ReaderTaskEither<R1 & R2, E2 | E1, A>
```

Added in v2.12.0

## apSecond

Combine two effectful actions, keeping only the result of the second.
Expand All @@ -367,6 +383,20 @@ export declare const apSecond: <R, E, B>(

Added in v2.0.0

## apSecondW

Less strict version of [`apSecond`](#apsecond).

**Signature**

```ts
export declare const apSecondW: <R2, E2, A, B>(
second: ReaderTaskEither<R2, E2, B>
) => <R1, E1>(first: ReaderTaskEither<R1, E1, A>) => ReaderTaskEither<R1 & R2, E2 | E1, B>
```

Added in v2.12.0

## asksReaderTaskEither

Effectfully accesses the environment.
Expand Down
24 changes: 24 additions & 0 deletions src/ReaderTaskEither.ts
Expand Up @@ -824,6 +824,18 @@ export const apFirst =
/*#__PURE__*/
apFirst_(ApplyPar)

/**
* Less strict version of [`apFirst`](#apfirst).
*
* @category combinators
* @since 2.12.0
*/
export const apFirstW: <R2, E2, A, B>(
second: ReaderTaskEither<R2, E2, B>
) => <R1, E1>(first: ReaderTaskEither<R1, E1, A>) => ReaderTaskEither<R1 & R2, E1 | E2, A> =
/*#__PURE__*/
apFirst as any

/**
* Combine two effectful actions, keeping only the result of the second.
*
Expand All @@ -836,6 +848,18 @@ export const apSecond =
/*#__PURE__*/
apSecond_(ApplyPar)

/**
* Less strict version of [`apSecond`](#apsecond).
*
* @category combinators
* @since 2.12.0
*/
export const apSecondW: <R2, E2, A, B>(
second: ReaderTaskEither<R2, E2, B>
) => <R1, E1>(first: ReaderTaskEither<R1, E1, A>) => ReaderTaskEither<R1 & R2, E1 | E2, B> =
/*#__PURE__*/
apSecond as any

/**
* @category instances
* @since 2.7.0
Expand Down
12 changes: 12 additions & 0 deletions test/ReaderTaskEither.ts
Expand Up @@ -31,10 +31,22 @@ describe('ReaderTaskEither', () => {
U.deepStrictEqual(await pipe(_.right('a'), _.apFirst(_.right('b')))({})(), E.right('a'))
})

it('apFirstW', async () => {
const fa = _.right<{ readonly k: string }, 'Foo', string>('a')
const fb = _.right<{ readonly x: number }, 'Bar', boolean>(true)
U.deepStrictEqual(await pipe(fa, _.apFirstW(fb))({ k: 'v', x: 42 })(), E.right('a'))
})

it('apSecond', async () => {
U.deepStrictEqual(await pipe(_.right('a'), _.apSecond(_.right('b')))({})(), E.right('b'))
})

it('apSecondW', async () => {
const fa = _.right<{ readonly k: string }, 'Foo', string>('a')
const fb = _.right<{ readonly x: number }, 'Bar', boolean>(true)
U.deepStrictEqual(await pipe(fa, _.apSecondW(fb))({ k: 'v', x: 42 })(), E.right(true))
})

it('chain', async () => {
const f = (a: string) => (a.length > 2 ? _.right(a.length) : _.left('b'))
U.deepStrictEqual(await pipe(_.right('aaa'), _.chain(f))({})(), E.right(3))
Expand Down

0 comments on commit 27d9a10

Please sign in to comment.