Commits

Iago Abal committed e5c19a3

Add and_ and or_ functions

  • Participants
  • Parent commits 67b817d

Comments (0)

Files changed (1)

File Data/BitVector.hs

   , foldl_, foldr_
   , reverse_
   , replicate_
+  , and_, or_
   , split, group_, join
   -- * Bitwise operations
   , module Data.Bits
 {-# SPECIALIZE replicate_ :: Int     -> BV -> BV #-}
 {-# SPECIALIZE replicate_ :: Integer -> BV -> BV #-}
 
+-- | Conjunction.
+--
+and_ :: [BV] -> BV
+and_ [] = error "Data.BitVector.and_: empty list"
+and_ ws = BV n' $ foldl1' (.&.) $ map nat ws
+  where n' = maximum $ map size ws
+{-# INLINE and_ #-}
+
+-- | Disjunction.
+--
+or_ :: [BV] -> BV
+or_ [] = error "Data.BitVector.or_: empty list"
+or_ ws = BV n' $ foldl1' (.|.) $ map nat ws
+  where n' = maximum $ map size ws
+{-# INLINE or_ #-}
+
 -- | Split a bit-vector /k/ times.
 --
 -- >>> split 3 [4]15