Skip to content

Commit

Permalink
StateReaderTaskEither: add apFirstW and apSecondW
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisFrezzato committed Oct 26, 2021
1 parent ffc0b4d commit 1a9cc14
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/modules/StateReaderTaskEither.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)
- [asksStateReaderTaskEither](#asksstatereadertaskeither)
- [asksStateReaderTaskEitherW](#asksstatereadertaskeitherw)
- [chainEitherK](#chaineitherk)
Expand Down Expand Up @@ -322,6 +324,20 @@ export declare const apFirst: <S, R, E, B>(

Added in v2.0.0

## apFirstW

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

**Signature**

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

Added in v2.12.0

## apSecond

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

Added in v2.0.0

## apSecondW

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

**Signature**

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

Added in v2.12.0

## asksStateReaderTaskEither

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

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

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

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

/**
* @category instances
* @since 2.7.0
Expand Down
14 changes: 14 additions & 0 deletions test/StateReaderTaskEither.ts
Expand Up @@ -61,11 +61,25 @@ describe('StateReaderTaskEither', () => {
U.deepStrictEqual(e, E.right('a'))
})

it('apFirstW', async () => {
const fa = _.right<unknown, { readonly k: string }, 'Foo', string>('a')
const fb = _.right<unknown, { readonly x: number }, 'Bar', number>(6)
const e = await pipe(fa, _.apFirstW(fb), _.evaluate(state))({ k: 'v', x: 5 })()
U.deepStrictEqual(e, E.right('a'))
})

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

it('apSecondW', async () => {
const fa = _.right<unknown, { readonly k: string }, 'Foo', string>('a')
const fb = _.right<unknown, { readonly x: number }, 'Bar', number>(6)
const e = await pipe(fa, _.apSecondW(fb), _.evaluate(state))({ k: 'v', x: 5 })()
U.deepStrictEqual(e, E.right(6))
})

it('chain', async () => {
const f = (s: string) => (s.length > 2 ? _.right(s.length) : _.right(0))
const e = await pipe(_.right('aaa'), _.chain(f), _.evaluate(state))({})()
Expand Down

0 comments on commit 1a9cc14

Please sign in to comment.