containers: intersections for Set, along with Semigroup newtype
Reed Mullanix
reedmullanix at gmail.com
Sun Dec 6 06:20:02 UTC 2020
Hey all,
I've found myself reaching for the following function a couple of times
now, so I figured it might make a good addition.
intersections :: Ord a => NonEmpty (Set a) -> Set a
intersections (s :| ss) = Foldable.foldl' intersection s ss
In a similar vein, we may as well add the following newtype + instance
combo:
newtype Intersection a = Intersection { getIntersection :: Set a }
instance (Ord a) => Semigroup (Intersection a) where
(Intersection a) <> (Intersection b) = Intersection $ intersection a b
stimes = stimesIdempotent
Would love to hear everyone's thoughts on this!
Thanks
Reed Mullanix
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20201205/fc3c268e/attachment.html>
More information about the Libraries
mailing list