Commits

Flaviu Andrei Csernik committed d3da513

Uncomment mapMonotonic from Set and add tests.

Relax type signature for mapKeysMonotonic.

  • Participants
  • Parent commits 2f3a088

Comments (0)

Files changed (3)

File Data/CritBit/Set.hs

 -- >                     ==> mapMonotonic f s == map f s
 -- >     where ls = toList s
 mapMonotonic :: (CritBitKey a2) => (a1 -> a2) -> Set a1 -> Set a2
-mapMonotonic = error "Depends on T.mapKeysMonotonic"
---mapMonotonic = wrapVS Set T.mapKeysMonotonic
+mapMonotonic = wrapVS Set T.mapKeysMonotonic
 {-# INLINABLE mapMonotonic #-}
 
 -- | /O(n)/. Fold the elements in the set using the given left-associative

File Data/CritBit/Tree.hs

 -- This function has slightly better performance than 'mapKeys'.
 --
 -- > mapKeysMonotonic (\ k -> succ k) (fromList [("a",5), ("b",3)]) == fromList [("b",5), ("c",3)]
-mapKeysMonotonic :: (CritBitKey k1, CritBitKey k2)
-                 => (k1 -> k2) -> CritBit k1 v -> CritBit k2 v
+mapKeysMonotonic :: CritBitKey k
+                 => (a -> k) -> CritBit a v -> CritBit k v
 mapKeysMonotonic f m = foldlWithKey (insertRight f) empty m
 {-# INLINABLE mapKeysMonotonic #-}
 

File tests/Properties/Set.hs

     partMap  = fixup Set.toList . Set.partition foo . Set.fromList $ ks
     foo = odd . byteCount
 
+t_mapMonotonic :: (CritBitKey k, Ord k, Monoid k, IsString k)
+               => k -> [k] -> Bool
+t_mapMonotonic = CS.mapMonotonic preps === Set.mapMonotonic preps
+  where preps = ("test" <>)
+
 propertiesFor :: (Arbitrary k, CritBitKey k, Ord k, Monoid k, Show k,
                   IsString k) => k -> [Test]
 propertiesFor t = [
   , testProperty "t_elems" $ t_elems t
   , testProperty "t_map" $ t_map t
   , testProperty "t_mapKeys" $ t_map t
+  , testProperty "t_mapMonotonic" $ t_mapMonotonic t
   , testProperty "t_toAscList" $ t_toAscList t
 #if MIN_VERSION_containers(0,5,0)
   , testProperty "t_toDescList" $ t_toDescList t