@@ -45,8 +45,6 @@ Set{Int64} with 3 elements:
4545"""
4646function union end
4747
48- _in (itr) = x -> x in itr
49-
5048union (s, sets... ) = union! (emptymutable (s, promote_eltype (s, sets... )), s, sets... )
5149union (s:: AbstractSet ) = copy (s)
5250
@@ -109,6 +107,10 @@ Maintain order with arrays.
109107
110108See also: [`setdiff`](@ref), [`isdisjoint`](@ref), [`issubset`](@ref Base.issubset), [`issetequal`](@ref).
111109
110+ !!! compat "Julia 1.8"
111+ As of Julia 1.8 intersect returns a result with the eltype of the
112+ type-promoted eltypes of the two inputs
113+
112114# Examples
113115```jldoctest
114116julia> intersect([1, 2, 3], [3, 4, 5])
@@ -125,9 +127,12 @@ Set{Int64} with 1 element:
125127 2
126128```
127129"""
128- intersect (s:: AbstractSet , itr, itrs... ) = intersect! (intersect (s, itr), itrs... )
130+ function intersect (s:: AbstractSet , itr, itrs... )
131+ T = promote_eltype (s, itr, itrs... )
132+ return intersect! (Set {T} (s), itr, itrs... )
133+ end
129134intersect (s) = union (s)
130- intersect (s:: AbstractSet , itr) = mapfilter (_in (s), push!, itr, emptymutable (s))
135+ intersect (s:: AbstractSet , itr) = mapfilter (in (s), push!, itr, emptymutable (s, promote_eltype (s, itr) ))
131136
132137const ∩ = intersect
133138
@@ -143,7 +148,7 @@ function intersect!(s::AbstractSet, itrs...)
143148 end
144149 return s
145150end
146- intersect! (s:: AbstractSet , s2:: AbstractSet ) = filter! (_in (s2), s)
151+ intersect! (s:: AbstractSet , s2:: AbstractSet ) = filter! (in (s2), s)
147152intersect! (s:: AbstractSet , itr) =
148153 intersect! (s, union! (emptymutable (s, eltype (itr)), itr))
149154
0 commit comments