@@ -3252,14 +3252,23 @@ const hashBucketsHas = (buckets: HashBuckets, value: unknown): boolean => {
32523252}
32533253
32543254/**
3255- * Computes the union of two arrays using a custom equivalence, removing
3256- * duplicates.
3255+ * Computes the union of two iterables using a custom equivalence.
32573256 *
32583257 * **When to use**
32593258 *
32603259 * Use when you need the union of two arrays but duplicate detection must use a
32613260 * custom equivalence instead of the default `Equal.asEquivalence()`.
32623261 *
3262+ * **Details**
3263+ *
3264+ * Keeps the elements of `self`, then appends elements of `that` that have no
3265+ * equivalent in `self`. Calls `isEquivalent` with an element from `self` first
3266+ * and an element from `that` second.
3267+ *
3268+ * **Gotchas**
3269+ *
3270+ * Each input must already be deduplicated.
3271+ *
32633272 * **Example** (Computing unions with custom equality)
32643273 *
32653274 * ```ts import.meta.vitest
@@ -3292,22 +3301,34 @@ export const unionWith: {
32923301 isEquivalent : ( self : A , that : B ) => boolean
32933302 ) : NonEmptyArray < A | B >
32943303 < A , B > ( self : Iterable < A > , that : Iterable < B > , isEquivalent : ( self : A , that : B ) => boolean ) : Array < A | B >
3295- } = dual ( 3 , < A > ( self : Iterable < A > , that : Iterable < A > , isEquivalent : ( self : A , that : A ) => boolean ) : Array < A > => {
3304+ } = dual ( 3 , < A , B > ( self : Iterable < A > , that : Iterable < B > , isEquivalent : ( self : A , that : B ) => boolean ) : Array < A | B > => {
32963305 const a = fromIterable ( self )
32973306 const b = fromIterable ( that )
32983307 if ( isReadonlyArrayNonEmpty ( a ) ) {
32993308 if ( isReadonlyArrayNonEmpty ( b ) ) {
3300- const dedupe = dedupeWith ( isEquivalent )
3301- return dedupe ( appendAll ( a , b ) )
3309+ const out : Array < A | B > = [ ...a ]
3310+ next: for ( const value of b ) {
3311+ for ( const candidate of a ) {
3312+ if ( isEquivalent ( candidate , value ) ) {
3313+ continue next
3314+ }
3315+ }
3316+ out . push ( value )
3317+ }
3318+ return out
33023319 }
33033320 return a
33043321 }
33053322 return b
33063323} )
33073324
33083325/**
3309- * Computes the union of two arrays, removing duplicates using
3310- * `Equal.asEquivalence()`.
3326+ * Computes the union of two iterables using `Equal.asEquivalence()`.
3327+ *
3328+ * **Gotchas**
3329+ *
3330+ * Each input must already be deduplicated. Use {@link dedupe} to remove
3331+ * duplicates from an input first.
33113332 *
33123333 * **Example** (Computing array unions)
33133334 *
0 commit comments