1module Network.HPACK.Huffman.Bit ( 2 -- * Bits 3 B(..) 4 , Bits 5 , fromBits 6 ) where 7 8import Imports 9 10-- | Data type for Bit. 11data B = F -- ^ Zero 12 | T -- ^ One 13 deriving (Eq,Ord,Show) 14 15-- | Bit stream. 16type Bits = [B] 17 18fromBit :: B -> Word8 19fromBit F = 0 20fromBit T = 1 21 22-- | From 'Bits' of length 8 to 'Word8'. 23-- 24-- >>> fromBits [T,F,T,F,T,F,T,F] 25-- 170 26-- >>> fromBits [F,T,F,T,F,T,F,T] 27-- 85 28fromBits :: Bits -> Word8 29fromBits = foldl' (\x y -> x * 2 + y) 0 . map fromBit 30