packages feed

WeakSets 1.1.0.0 → 1.1.1.0

raw patch · 3 files changed

+22/−6 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.WeakMap: foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
- Data.WeakMap: foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
- Data.WeakMap: null :: Foldable t => t a -> Bool
- Data.WeakMap: drop :: Int -> [a] -> [a]
+ Data.WeakMap: drop :: Eq k => Int -> Map k a -> Map k a
- Data.WeakMap: splitAt :: Int -> [a] -> ([a], [a])
+ Data.WeakMap: splitAt :: Eq k => Int -> Map k a -> (Map k a, Map k a)
- Data.WeakMap: take :: Int -> [a] -> [a]
+ Data.WeakMap: take :: Eq k => Int -> Map k a -> Map k a

Files

CHANGELOG.md view
@@ -10,4 +10,8 @@ 
 # 1.1.0.0 -- 2022-07-19
 
-* Correction of wrong function declaration of (|^|)+* Correction of wrong function declaration of (|^|)
+
+# 1.1.1.0 -- 2022-07-19
+
+* Implementation of drop, take and splitAt
WeakSets.cabal view
@@ -14,7 +14,7 @@ -- PVP summary:      +-+------- breaking API changes
 --                   | | +----- non-breaking API additions
 --                   | | | +--- code changes with no API change
-version:            1.1.0.0
+version:            1.1.1.0
 
 -- A short (one-line) description of the package.
 synopsis:
src/Data/WeakMap.hs view
@@ -100,7 +100,6 @@     , notMember
 
     -- ** Size
-    , null
     , size
 
     -- * Combine
@@ -146,8 +145,6 @@     , mapKeysMonotonic
 
     -- * Folds
-    , foldr
-    , foldl
     , foldrWithKey
     , foldlWithKey
     , foldMapWithKey
@@ -210,7 +207,7 @@     , idFromSet
     , memorizeFunction
 ) where
-import           Prelude  hiding      (lookup, map, filter)
+import           Prelude  hiding      (lookup, map, filter, drop, take, splitAt)
 import           Data.WeakSet         (Set)
 import qualified Data.WeakSet       as Set
 import           Data.WeakSet.Safe
@@ -874,6 +871,21 @@         helper _ [] = []
         helper 0 (x:xs) = xs
         helper n (x:xs) = helper (n-1) xs
+
+-- | /O(n^2)/. Take a given number of pairs to create a new map.
+take :: (Eq k) => Int -> Map k a -> Map k a
+take n m = fst $ splitAt n m
+
+-- | /O(n^2)/. Drop a given number of pairs to create a new map.
+drop :: (Eq k) => Int -> Map k a -> Map k a
+drop n m = snd $ splitAt n m
+
+-- | /O(n^2)/. Split a map at a particular index.
+splitAt :: (Eq k) => Int -> Map k a -> (Map k a, Map k a)
+splitAt n m = (Map $ set l, Map $ set r)
+    where
+        al = mapToList m
+        (l,r) = L.splitAt n al
 
 
 -- Others