@@ -7,6 +7,9 @@ module Main (main) where
7
7
8
8
import Control.Monad ( guard )
9
9
import qualified Data.Foldable as Foldable
10
+ #if MIN_VERSION_base(4,10,0)
11
+ import Data.Bifoldable
12
+ #endif
10
13
import Data.Function (on )
11
14
import Data.Hashable (Hashable (hashWithSalt ))
12
15
import qualified Data.List as L
@@ -291,6 +294,23 @@ pFoldr = (L.sort . M.foldr (:) []) `eq` (L.sort . HM.foldr (:) [])
291
294
pFoldl :: [(Int , Int )] -> Bool
292
295
pFoldl = (L. sort . M. foldl (flip (:) ) [] ) `eq` (L. sort . HM. foldl (flip (:) ) [] )
293
296
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
+
294
314
pFoldrWithKey :: [(Int , Int )] -> Bool
295
315
pFoldrWithKey = (sortByKey . M. foldrWithKey f [] ) `eq`
296
316
(sortByKey . HM. foldrWithKey f [] )
@@ -414,6 +434,11 @@ tests =
414
434
, testGroup " folds"
415
435
[ testProperty " foldr" pFoldr
416
436
, 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
417
442
, testProperty " foldrWithKey" pFoldrWithKey
418
443
, testProperty " foldlWithKey" pFoldlWithKey
419
444
, testProperty " foldrWithKey'" pFoldrWithKey'
0 commit comments