Skip to content
Snippets Groups Projects
Commit 7985849b authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Add Bag.anyBag (analogous to List.any)

parent 04fd7141
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,7 @@ module Bag ( ...@@ -11,7 +11,7 @@ module Bag (
mapBag, mapBag,
elemBag, elemBag,
filterBag, partitionBag, concatBag, foldBag, foldrBag, foldlBag, filterBag, partitionBag, concatBag, foldBag, foldrBag, foldlBag,
isEmptyBag, isSingletonBag, consBag, snocBag, isEmptyBag, isSingletonBag, consBag, snocBag, anyBag,
listToBag, bagToList, listToBag, bagToList,
mapBagM, mapAndUnzipBagM mapBagM, mapAndUnzipBagM
) where ) where
...@@ -75,6 +75,12 @@ filterBag pred (TwoBags b1 b2) = sat1 `unionBags` sat2 ...@@ -75,6 +75,12 @@ filterBag pred (TwoBags b1 b2) = sat1 `unionBags` sat2
sat2 = filterBag pred b2 sat2 = filterBag pred b2
filterBag pred (ListBag vs) = listToBag (filter pred vs) filterBag pred (ListBag vs) = listToBag (filter pred vs)
anyBag :: (a -> Bool) -> Bag a -> Bool
anyBag p EmptyBag = False
anyBag p (UnitBag v) = p v
anyBag p (TwoBags b1 b2) = anyBag p b1 || anyBag p b2
anyBag p (ListBag xs) = any p xs
concatBag :: Bag (Bag a) -> Bag a concatBag :: Bag (Bag a) -> Bag a
concatBag EmptyBag = EmptyBag concatBag EmptyBag = EmptyBag
concatBag (UnitBag b) = b concatBag (UnitBag b) = b
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment