Skip to content

Commit

Permalink
TaskEither: 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 0ed29e6 commit 32820bd
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/modules/TaskEither.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Added in v2.0.0
- [of](#of)
- [combinators](#combinators)
- [apFirst](#apfirst)
- [apFirstW](#apfirstw)
- [apSecond](#apsecond)
- [apSecondW](#apsecondw)
- [chainEitherK](#chaineitherk)
- [chainEitherKW](#chaineitherkw)
- [chainFirst](#chainfirst)
Expand Down Expand Up @@ -355,6 +357,20 @@ export declare const apFirst: <E, B>(second: TaskEither<E, B>) => <A>(first: Tas

Added in v2.0.0

## apFirstW

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

**Signature**

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

Added in v2.12.0

## apSecond

Combine two effectful actions, keeping only the result of the second.
Expand All @@ -369,6 +385,20 @@ export declare const apSecond: <E, B>(second: TaskEither<E, B>) => <A>(first: Ta

Added in v2.0.0

## apSecondW

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

**Signature**

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

Added in v2.12.0

## chainEitherK

**Signature**
Expand Down
24 changes: 24 additions & 0 deletions src/TaskEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,18 @@ export const apFirst =
/*#__PURE__*/
apFirst_(ApplyPar)

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

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

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

/**
* @category instances
* @since 2.7.0
Expand Down
14 changes: 14 additions & 0 deletions test/TaskEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,24 @@ describe('TaskEither', () => {
U.deepStrictEqual(await pipe(_.right('a'), _.apFirst(_.right('b')))(), E.right('a'))
})

it('apFirstW', async () => {
U.deepStrictEqual(
await pipe(_.right<number, string>('foo'), _.apFirstW(_.right<string, boolean>(true)))(),
E.right('foo')
)
})

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

it('apSecondW', async () => {
U.deepStrictEqual(
await pipe(_.right<number, string>('foo'), _.apSecondW(_.right<string, boolean>(true)))(),
E.right(true)
)
})

it('chain', async () => {
U.deepStrictEqual(
await pipe(
Expand Down

0 comments on commit 32820bd

Please sign in to comment.