@@ -7,6 +7,9 @@ module Main (main) where
77
88import Control.Monad ( guard )
99import qualified Data.Foldable as Foldable
10+ #if MIN_VERSION_base(4,10,0)
11+ import Data.Bifoldable
12+ #endif
1013import Data.Function (on )
1114import Data.Hashable (Hashable (hashWithSalt ))
1215import qualified Data.List as L
@@ -291,6 +294,23 @@ pFoldr = (L.sort . M.foldr (:) []) `eq` (L.sort . HM.foldr (:) [])
291294pFoldl :: [(Int , Int )] -> Bool
292295pFoldl = (L. sort . M. foldl (flip (:) ) [] ) `eq` (L. sort . HM. foldl (flip (:) ) [] )
293296
297+ #if MIN_VERSION_base(4,10,0)
298+ pBifoldMap :: [(Int , Int )] -> Bool
299+ pBifoldMap xs = concatMap f (HM. toList m) == bifoldMap (: [] ) (: [] ) m
300+ where f (k, v) = [k, v]
301+ m = HM. fromList xs
302+
303+ pBifoldr :: [(Int , Int )] -> Bool
304+ pBifoldr xs = concatMap f (HM. toList m) == bifoldr (:) (:) [] m
305+ where f (k, v) = [k, v]
306+ m = HM. fromList xs
307+
308+ pBifoldl :: [(Int , Int )] -> Bool
309+ pBifoldl xs = reverse (concatMap f $ HM. toList m) == bifoldl (flip (:) ) (flip (:) ) [] m
310+ where f (k, v) = [k, v]
311+ m = HM. fromList xs
312+ #endif
313+
294314pFoldrWithKey :: [(Int , Int )] -> Bool
295315pFoldrWithKey = (sortByKey . M. foldrWithKey f [] ) `eq`
296316 (sortByKey . HM. foldrWithKey f [] )
@@ -414,6 +434,11 @@ tests =
414434 , testGroup " folds"
415435 [ testProperty " foldr" pFoldr
416436 , testProperty " foldl" pFoldl
437+ #if MIN_VERSION_base(4,10,0)
438+ , testProperty " bifoldMap" pBifoldMap
439+ , testProperty " bifoldr" pBifoldr
440+ , testProperty " bifoldl" pBifoldl
441+ #endif
417442 , testProperty " foldrWithKey" pFoldrWithKey
418443 , testProperty " foldlWithKey" pFoldlWithKey
419444 , testProperty " foldrWithKey'" pFoldrWithKey'
0 commit comments