import qualified Data.ByteString.Builder.Prim as P
filterBS p = P.condB p (P.liftFixedToBounded P.word8) P.emptyB
mapToBuilder :: (Word8 -> Word8) -> S.ByteString -> Builder mapToBuilder f = primMapByteStringFixed (contramapF f word8)We can also use it to hex-encode a strict ByteString as shown by the byteStringHex example above.
mconcat . map (primBounded w)or
foldMap (primBounded w)because it moves several variables out of the inner loop.
contramapB id = id contramapB f . contramapB g = contramapB (g . f)
contramapF id = id contramapF f . contramapF g = contramapF (g . f)