Skip to content

Commit

Permalink
NonEmptyProduct: rename bindKind to andThenBind
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored and mikearnaldi committed Nov 3, 2022
1 parent 374b1c2 commit 07b7061
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-timers-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fp-ts/core": patch
---

NonEmptyProduct: rename bindKind to andThenBind
2 changes: 1 addition & 1 deletion Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ Extends:
| productManyComposition | `F<G<A>>`, `Iterable<F<G<A>>>` | `F<G<[A, ...ReadonlyArray<A>]>>` |
| nonEmptyTuple | `[F<A>, F<B>, ...]` | `F<[A, B, ...]>` |
| nonEmptyStruct | `{ a: F<A>, b: F<B>, ... }` | `F<{ a: A, b: B, ... }>` |
| bindKind | `F<A>`, `name: string`, `F<B>` | `F<A & { [name]: B }>` |
| andThenBind | `F<A>`, `name: string`, `F<B>` | `F<A & { [name]: B }>` |
| productFlatten | `F<A>`, `F<B>` | `F<[...A, B]>` |

### NonEmptyTraversable
Expand Down
2 changes: 1 addition & 1 deletion src/typeclass/NonEmptyProduct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const productMany = <F extends TypeLambda>(
/**
* @since 1.0.0
*/
export const bindKind = <F extends TypeLambda>(F: NonEmptyProduct<F>) =>
export const andThenBind = <F extends TypeLambda>(F: NonEmptyProduct<F>) =>
<N extends string, A extends object, R2, O2, E2, B>(
name: Exclude<N, keyof A>,
fb: Kind<F, R2, O2, E2, B>
Expand Down
4 changes: 2 additions & 2 deletions test/test-data/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1063,11 +1063,11 @@ export const bind: <N extends string, A extends object, B>(
* @category do notation
* @since 1.0.0
*/
export const bindOption: <N extends string, A extends object, B>(
export const andThenBind: <N extends string, A extends object, B>(
name: Exclude<N, keyof A>,
fb: Option<B>
) => (self: Option<A>) => Option<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }> =
nonEmptyProduct.bindKind(NonEmptyApplicative)
nonEmptyProduct.andThenBind(NonEmptyApplicative)

// -------------------------------------------------------------------------------------
// tuple sequencing
Expand Down
4 changes: 2 additions & 2 deletions test/test-data/Predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ export const Product: product.Product<PredicateTypeLambda> = {
}
}

export const bindPredicate: <N extends string, A extends object, B>(
export const andThenBind: <N extends string, A extends object, B>(
name: Exclude<N, keyof A>,
fb: Predicate<B>
) => (
self: Predicate<A>
) => Predicate<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }> = nonEmptyProduct
.bindKind(
.andThenBind(
NonEmptyProduct
)

Expand Down
12 changes: 6 additions & 6 deletions test/typeclass/NonEmptyProduct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,18 @@ describe("NonEmptyProduct", () => {
})
})

describe("bindKind", () => {
describe("andThenBind", () => {
it("Covariant (Option)", () => {
const bindKind = _.bindKind(O.Applicative)
U.deepStrictEqual(pipe(O.some({ a: 1 }), bindKind("b", O.none)), O.none)
U.deepStrictEqual(pipe(O.some({ a: 1 }), bindKind("b", O.some(2))), O.some({ a: 1, b: 2 }))
const andThenBind = _.andThenBind(O.Applicative)
U.deepStrictEqual(pipe(O.some({ a: 1 }), andThenBind("b", O.none)), O.none)
U.deepStrictEqual(pipe(O.some({ a: 1 }), andThenBind("b", O.some(2))), O.some({ a: 1, b: 2 }))
})

it("Contravariant (Predicate)", () => {
const p = pipe(
P.Do,
P.bindPredicate("x", P.isString),
P.bindPredicate("y", P.isNumber)
P.andThenBind("x", P.isString),
P.andThenBind("y", P.isNumber)
)
U.deepStrictEqual(p({ x: "a", y: 1 }), true)
U.deepStrictEqual(p({ x: "a", y: "x" }), false)
Expand Down

0 comments on commit 07b7061

Please sign in to comment.