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

fix since tags #3844

Merged
merged 1 commit into from
Oct 25, 2024
Merged
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
24 changes: 18 additions & 6 deletions packages/typeclass/src/data/Record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@ export const getTraversableFilterable = <K extends string>(): traversableFiltera
export const TraversableFilterable = getTraversableFilterable()

/**
* A `Semigroup` that creates an union of two records.
* A `Semigroup` that creates a union of two records.
*
* This `Semigroup` takes two records and combines them into a single record.
* If a key exists in both records, the provided `Semigroup` instance is used to combine the values for that key.
* If a key exists in only one of the records, that key-value pair is included as is in the resulting record.
*
* For example, when using the `MonoidSum`, values for matching keys will be summed.
*
* @example
* import * as NumberInstances from "@effect/typeclass/data/Number"
Expand All @@ -214,17 +220,20 @@ export const TraversableFilterable = getTraversableFilterable()
* assert.deepStrictEqual(getSemigroupUnion(NumberInstances.MonoidSum).combine({ a: 1 }, { a: 1, b: 3 }), { a: 2, b: 3 })
*
* @category instances
* @since 0.29.3
* @since 0.29.4
*/
export const getSemigroupUnion: <A>(
value: semigroup.Semigroup<A>
) => semigroup.Semigroup<Record.ReadonlyRecord<string, A>> = <A>(value: semigroup.Semigroup<A>) =>
semigroup.make<Record<string, A>>((self, that) => Record.union(self, that, value.combine))

/**
* A `Monoid` that creates an union of two records.
* A `Monoid` that creates a union of two records.
*
* The `empty` value is `{}`.
* It allows combining two records where values for matching keys are combined using the provided `Monoid` instance.
* If a key exists in only one of the records, that key-value pair is included as is in the resulting record.
*
* The `empty` value for this `Monoid` is an empty record `{}`.
*
* @example
* import * as NumberInstances from "@effect/typeclass/data/Number"
Expand All @@ -236,7 +245,7 @@ export const getSemigroupUnion: <A>(
* assert.deepStrictEqual(monoid.combine({ a: 1 }, monoid.empty), { a: 1 })
*
* @category instances
* @since 0.29.3
* @since 0.29.4
*/
export const getMonoidUnion: <A>(
value: monoid.Monoid<A>
Expand All @@ -246,14 +255,17 @@ export const getMonoidUnion: <A>(
/**
* A `Semigroup` that creates an intersection of two records.
*
* This `Semigroup` takes two records and combines them into a new record containing only the keys that are present in both records.
* The values for matching keys are combined using the provided `Semigroup` instance.
*
* @example
* import * as NumberInstances from "@effect/typeclass/data/Number"
* import { getSemigroupIntersection } from "@effect/typeclass/data/Record"
*
* assert.deepStrictEqual(getSemigroupIntersection(NumberInstances.MonoidSum).combine({ a: 1 }, { a: 1, b: 3 }), { a: 2 })
*
* @category instances
* @since 0.29.3
* @since 0.29.4
*/
export const getSemigroupIntersection: <A>(
value: semigroup.Semigroup<A>
Expand Down