Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chainFirstEitherK(W) in ReaderTaskEither module #1562

Merged
merged 1 commit into from Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chainFirstEitherKW - chain - first - either - k - w, man this is crazy 😂

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There already are also chainFirstTaskEitherKW, chainFirstReaderEitherKW and chainFirstReaderTaskKW among others...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

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