@@ -155,6 +155,7 @@ module Data.Set.Internal (
155
155
, unions
156
156
, difference
157
157
, intersection
158
+ , intersections
158
159
, cartesianProduct
159
160
, disjointUnion
160
161
@@ -234,10 +235,11 @@ import Control.Applicative (Const(..))
234
235
import qualified Data.List as List
235
236
import Data.Bits (shiftL , shiftR )
236
237
import Data.Semigroup (Semigroup (stimes ))
238
+ import Data.List.NonEmpty (NonEmpty (.. ))
237
239
#if !(MIN_VERSION_base(4,11,0))
238
240
import Data.Semigroup (Semigroup ((<>) ))
239
241
#endif
240
- import Data.Semigroup (stimesIdempotentMonoid )
242
+ import Data.Semigroup (stimesIdempotentMonoid , stimesIdempotent )
241
243
import Data.Functor.Classes
242
244
import Data.Functor.Identity (Identity )
243
245
import qualified Data.Foldable as Foldable
@@ -875,6 +877,20 @@ intersection t1@(Bin _ x l1 r1) t2
875
877
{-# INLINABLE intersection #-}
876
878
#endif
877
879
880
+ #if (MIN_VERSION_base(4,9,0))
881
+ -- | The intersection of a series of sets.
882
+ intersections :: Ord a => NonEmpty (Set a ) -> Set a
883
+ intersections (s :| ss) = Foldable. foldl' intersection s ss
884
+
885
+ -- | Sets form a 'Semigroup' under 'intersection'.
886
+ newtype Intersection a = Intersection { getIntersection :: Set a }
887
+ deriving (Show , Eq , Ord )
888
+
889
+ instance (Ord a ) => Semigroup (Intersection a ) where
890
+ (Intersection a) <> (Intersection b) = Intersection $ intersection a b
891
+ stimes = stimesIdempotent
892
+ #endif
893
+
878
894
{- -------------------------------------------------------------------
879
895
Filter and partition
880
896
--------------------------------------------------------------------}
0 commit comments