Skip to content

Commit d0c9173

Browse files
TOTBWFtreeowl
authored andcommitted
Improve the laziness properties of intersections
1 parent eb6cf52 commit d0c9173

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

containers/src/Data/Set/Internal.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,11 @@ intersection t1@(Bin _ x l1 r1) t2
886886
#if (MIN_VERSION_base(4,9,0))
887887
-- | The intersection of a series of sets. Intersections are performed left-to-right.
888888
intersections :: Ord a => NonEmpty (Set a) -> Set a
889-
intersections (s :| ss) = Foldable.foldl' intersection s ss
889+
intersections (s0 :| ss) = List.foldr go id ss s0
890+
where
891+
go s r acc
892+
| null acc = empty
893+
| otherwise = r (intersection acc s)
890894

891895
-- | Sets form a 'Semigroup' under 'intersection'.
892896
newtype Intersection a = Intersection { getIntersection :: Set a }

0 commit comments

Comments
 (0)