Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions docs/modules/ReaderTaskEither.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,15 @@ Added in v2.0.0
- [utils](#utils)
- [ApT](#apt)
- [ap](#ap)
- [apEitherSK](#apeithersk)
- [apEitherSKW](#apeitherskw)
- [apFirst](#apfirst)
- [apFirstW](#apfirstw)
- [apSecond](#apsecond)
- [apSecondW](#apsecondw)
- [apW](#apw)
- [bindEitherK](#bindeitherk)
- [bindEitherKW](#bindeitherkw)
- [bracket](#bracket)
- [bracketW](#bracketw)
- [local](#local)
Expand Down Expand Up @@ -2025,6 +2029,36 @@ export declare const ap: <R, E, A>(

Added in v2.0.0

## apEitherSK

**Signature**

```ts
export declare const apEitherSK: <A, N extends string, R, E, B>(
name: Exclude<N, keyof A>,
f: E.Either<E, B>
) => (
fa: ReaderTaskEither<R, E, A>
) => ReaderTaskEither<R, E, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
```

Added in v2.13.0

## apEitherSKW

**Signature**

```ts
export declare const apEitherSKW: <N extends string, A, E2, B>(
name: Exclude<N, keyof A>,
f: E.Either<E2, B>
) => <R1, E1>(
fa: ReaderTaskEither<R1, E1, A>
) => ReaderTaskEither<R1, E2 | E1, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
```

Added in v2.13.0

## apFirst

Combine two effectful actions, keeping only the result of the first.
Expand Down Expand Up @@ -2101,6 +2135,36 @@ export declare const apW: <R2, E2, A>(

Added in v2.8.0

## bindEitherK

**Signature**

```ts
export declare const bindEitherK: <N extends string, A, R, E, B>(
name: Exclude<N, keyof A>,
f: (a: A) => E.Either<E, B>
) => (
ma: ReaderTaskEither<R, E, A>
) => ReaderTaskEither<R, E, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
```

Added in v2.13.0

## bindEitherKW

**Signature**

```ts
export declare const bindEitherKW: <N extends string, A, E2, B>(
name: Exclude<N, keyof A>,
f: (a: A) => E.Either<E2, B>
) => <R1, E1>(
fa: ReaderTaskEither<R1, E1, A>
) => ReaderTaskEither<R1, E2 | E1, { readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
```

Added in v2.13.0

## bracket

Make sure that a resource is cleaned up in the event of an exception (\*). The release action is called regardless of
Expand Down
32 changes: 32 additions & 0 deletions src/ReaderTaskEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,22 @@ export const bindW: <N extends string, A, R2, E2, B>(
fa: ReaderTaskEither<R1, E1, A>
) => ReaderTaskEither<R1 & R2, E1 | E2, { readonly [K in keyof A | N]: K extends keyof A ? A[K] : B }> = bind as any

/**
* @since 2.13.0
*/
export const bindEitherK = <N extends string, A, R, E, B>(name: Exclude<N, keyof A>, f: (a: A) => Either<E, B>) =>
bind(name, (a) => fromEither<E, B, R>(f(a)))

/**
* @since 2.13.0
*/
export const bindEitherKW: <N extends string, A, E2, B>(
name: Exclude<N, keyof A>,
f: (a: A) => Either<E2, B>
) => <R1, E1>(
fa: ReaderTaskEither<R1, E1, A>
) => ReaderTaskEither<R1, E1 | E2, { readonly [K in keyof A | N]: K extends keyof A ? A[K] : B }> = bindEitherK as any

/**
* @category do notation
* @since 2.8.0
Expand All @@ -1504,6 +1520,22 @@ export const apSW: <A, N extends string, R2, E2, B>(
fa: ReaderTaskEither<R1, E1, A>
) => ReaderTaskEither<R1 & R2, E1 | E2, { readonly [K in keyof A | N]: K extends keyof A ? A[K] : B }> = apS as any

/**
* @since 2.13.0
*/
export const apEitherSK = <A, N extends string, R, E, B>(name: Exclude<N, keyof A>, f: Either<E, B>) =>
apS(name, fromEither<E, B, R>(f))

/**
* @since 2.13.0
*/
export const apEitherSKW: <N extends string, A, E2, B>(
name: Exclude<N, keyof A>,
f: Either<E2, B>
) => <R1, E1>(
fa: ReaderTaskEither<R1, E1, A>
) => ReaderTaskEither<R1, E1 | E2, { readonly [K in keyof A | N]: K extends keyof A ? A[K] : B }> = apEitherSK as any

/**
* @since 2.11.0
*/
Expand Down
24 changes: 24 additions & 0 deletions test/ReaderTaskEither.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,37 @@ describe('ReaderTaskEither', () => {
)
})

it('bindEitherK', async () => {
U.deepStrictEqual(
await pipe(
_.right<void, string, number>(1),
_.bindTo('a'),
_.bindEitherK('b', () => E.right<string, string>('b')),
_.bindEitherKW('c', () => E.right<number, string>('c'))
)(undefined)(),
E.right({ a: 1, b: 'b', c: 'c' })
)
})

it('apS', async () => {
U.deepStrictEqual(
await pipe(_.right<void, string, number>(1), _.bindTo('a'), _.apS('b', _.right('b')))(undefined)(),
E.right({ a: 1, b: 'b' })
)
})

it('apEitherSK', async () => {
U.deepStrictEqual(
await pipe(
_.right<void, string, number>(1),
_.bindTo('a'),
_.apEitherSK('b', E.right<string, string>('b')),
_.apEitherSKW('c', E.right<number, string>('c'))
)(undefined)(),
E.right({ a: 1, b: 'b', c: 'c' })
)
})

describe('array utils', () => {
const input: ReadonlyNonEmptyArray<string> = ['a', 'b']

Expand Down