module Data.Bitmask (foldFlags) where import Prelude hiding (foldl) import Data.Bits import Data.Foldable foldFlags :: (Bits b, Foldable f, Num b) => (flag -> b) -> f flag -> b foldFlags :: forall b (f :: Type -> Type) flag. (Bits b, Foldable f, Num b) => (flag -> b) -> f flag -> b foldFlags flag -> b f = forall (t :: Type -> Type) b a. Foldable t => (b -> a -> b) -> b -> t a -> b foldl (\b a flag b -> b a forall a. Bits a => a -> a -> a .|. flag -> b f flag b) b 0