From 7985849b10db59b566d1864075b97b5d11d3a31d Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Fri, 3 Feb 2006 17:46:27 +0000 Subject: [PATCH] Add Bag.anyBag (analogous to List.any) --- ghc/compiler/utils/Bag.lhs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ghc/compiler/utils/Bag.lhs b/ghc/compiler/utils/Bag.lhs index 4ee8b0f..b107f84 100644 --- a/ghc/compiler/utils/Bag.lhs +++ b/ghc/compiler/utils/Bag.lhs @@ -11,7 +11,7 @@ module Bag ( mapBag, elemBag, filterBag, partitionBag, concatBag, foldBag, foldrBag, foldlBag, - isEmptyBag, isSingletonBag, consBag, snocBag, + isEmptyBag, isSingletonBag, consBag, snocBag, anyBag, listToBag, bagToList, mapBagM, mapAndUnzipBagM ) where @@ -75,6 +75,12 @@ filterBag pred (TwoBags b1 b2) = sat1 `unionBags` sat2 sat2 = filterBag pred b2 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 EmptyBag = EmptyBag concatBag (UnitBag b) = b -- 1.7.10.4