Skip to content

Commit

Permalink
Add chainFirstEitherK(W) in ReaderTaskEither module
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisFrezzato committed Oct 31, 2021
1 parent d2ba65a commit 45ed8a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/ReaderTaskEither.ts
Expand Up @@ -1156,6 +1156,24 @@ export const chainEitherKW: <E2, A, B>(
f: (a: A) => Either<E2, B>
) => <R, E1>(ma: ReaderTaskEither<R, E1, A>) => ReaderTaskEither<R, E1 | E2, B> = chainEitherK as any

/**
* Less strict version of [`chainFirstEitherK`](#chainfirsteitherk).
*
* @category combinators
* @since 2.12.0
*/
export const chainFirstEitherKW: <E2, A, B>(
f: (a: A) => Either<E2, B>
) => <R, E1>(ma: ReaderTaskEither<R, E1, A>) => ReaderTaskEither<R, E1 | E2, A> = (f) => chainFirstW(fromEitherK(f))

/**
* @category combinators
* @since 2.12.0
*/
export const chainFirstEitherK: <E, A, B>(
f: (a: A) => Either<E, B>
) => <R>(ma: ReaderTaskEither<R, E, A>) => ReaderTaskEither<R, E, A> = chainFirstEitherKW

/**
* @category constructors
* @since 2.0.0
Expand Down
5 changes: 5 additions & 0 deletions test/ReaderTaskEither.ts
Expand Up @@ -420,6 +420,11 @@ describe('ReaderTaskEither', () => {
U.deepStrictEqual(await pipe(_.right('a'), _.chainEitherK(f))(undefined)(), E.right(1))
})

it('chainFirstEitherKW', async () => {
const f = (s: string) => E.right<string, number>(s.length)
U.deepStrictEqual(await pipe(_.right<{}, number, string>('a'), _.chainFirstEitherKW(f))({})(), E.right('a'))
})

it('chainIOEitherK', async () => {
const f = (s: string) => IE.right(s.length)
U.deepStrictEqual(await pipe(_.right('a'), _.chainIOEitherK(f))(undefined)(), E.right(1))
Expand Down

0 comments on commit 45ed8a9

Please sign in to comment.