packages feed

WeakSets 1.2.4.0 → 1.3.0.0

raw patch · 4 files changed

+11/−8 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.WeakSet: cartesianProductOfSet :: Set (Set a) -> Set (Set a)
- Data.WeakSet.Safe: cartesianProductOfSet :: Set (Set a) -> Set (Set a)
+ Data.WeakSet: cartesianProductOfSets :: (Monoid (m a), Monad m, Foldable m, Eq a) => m (Set a) -> Set (m a)
+ Data.WeakSet.Safe: cartesianProductOfSets :: (Monoid (m a), Monad m, Foldable m, Eq a) => m (Set a) -> Set (m a)

Files

CHANGELOG.md view
@@ -46,4 +46,8 @@ 
 # 1.2.4.0 -- 2022-07-26
 
-* Adding Alternative instance+* Adding Alternative instance
+
+# 1.3.0.0 -- 2022-07-28
+
+* Correction of cartesianProductOfSet
WeakSets.cabal view
@@ -14,7 +14,7 @@ -- PVP summary:      +-+------- breaking API changes
 --                   | | +----- non-breaking API additions
 --                   | | | +--- code changes with no API change
-version:            1.2.4.0
+version:            1.3.0.0
 
 -- A short (one-line) description of the package.
 synopsis:
src/Data/WeakSet.hs view
@@ -164,7 +164,7 @@     , traverseSet
     , sequenceSet
     , anElement
-    , cartesianProductOfSet
+    , cartesianProductOfSets
     
 ) where
 import              Prelude         hiding (filter, splitAt, drop, take, map, foldr, foldl, length, elem, maximum, minimum, sum, product, concat, concatMap, and, or, any, all, maximumBy, minimumBy, notElem, find, null)
@@ -555,10 +555,9 @@ anElement (Set []) = error "Data.WeakSet.anElement: empty set"
 anElement (Set (x:xs)) = x
 
--- | Return the cartesian product of a set of set.
-cartesianProductOfSet :: Set (Set a) -> Set (Set a)
-cartesianProductOfSet (Set []) = Set ([Set []])
-cartesianProductOfSet (Set (x:xs)) = (\(y,ys) -> insert y ys) <$>  x |*| (cartesianProductOfSet (Set xs))
+-- | Return the cartesian product of a collection of sets.
+cartesianProductOfSets :: (Monoid (m a), Monad m, Foldable m, Eq a) => m (Set a) -> Set (m a)
+cartesianProductOfSets t = Foldable.foldr (\s result -> ((<>).pure <$> s) <*> result) (set $ pure $ mempty) t 
 
 -- | /O(n^2)/. Fold the elements in the set using the given right-associative binary operator.
 --
src/Data/WeakSet/Safe.hs view
@@ -25,7 +25,7 @@     (|^|),
     nubSetBy,
     anElement,
-    cartesianProductOfSet,
+    cartesianProductOfSets,
 )
 where
     import              Data.WeakSet