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 53929ce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "fp-ts",
"version": "2.11.5",
"version": "2.11.4",
"description": "Functional programming in TypeScript",
"main": "lib/index.js",
"module": "es6/index.js",
Expand Down
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 53929ce

Please sign in to comment.