pack (or unpack) a list of bytes into a ByteString
packedBytes ≡ re unpackedBytes
pack x ≡ x ^. packedBytes
unpack x ≡ x ^. re packedBytes
[104,101,108,108,111] ^. packedBytes"hello"
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27
Moduleoptics-extra-0.4.2.1Haskell2010
pack (or unpack) a list of bytes into a ByteString
packedBytes ≡ re unpackedBytes
pack x ≡ x ^. packedBytes
unpack x ≡ x ^. re packedBytes
[104,101,108,108,111] ^. packedBytes"hello"
unpack (or pack) a ByteString into a list of bytes.
unpackedBytes ≡ re packedBytes
unpack x ≡ x ^. unpackedBytes
pack x ≡ x ^. re unpackedBytes
"hello" ^. packedChars % unpackedBytes[104,101,108,108,111]
Traverse each Word8 in a ByteString.
This Traversal walks the ByteString in a tree-like fashion enable zippers to seek to locations in logarithmic time and accelerating many monoidal queries, but up to associativity (and constant factors) it is equivalent to the much slower:
bytes ≡ unpackedBytes % traversed
anyOf bytes (== 0x80) (Char8.pack "hello")False
Note that when just using this as a Setter, sets map
can be more efficient.
pack (or unpack) a list of characters into a ByteString
When writing back to the ByteString it is assumed that every Char lies
between 'x00' and 'xff'.
packedChars ≡ re unpackedChars
pack x ≡ x ^. packedChars
unpack x ≡ x ^. re packedChars
foldOf (packedChars % each % to (\w -> let x = showHex w "" in if Prelude.length x == 1 then '0':x else x)) "hello""68656c6c6f"
unpack (or pack) a list of characters into a ByteString
When writing back to the ByteString it is assumed that every Char lies
between 'x00' and 'xff'.
unpackedChars ≡ re packedChars
unpack x ≡ x ^. unpackedChars
pack x ≡ x ^. re unpackedChars
[104,101,108,108,111] ^. packedBytes % unpackedChars"hello"
Traverse the individual bytes in a ByteString as characters.
When writing back to the ByteString it is assumed that every Char lies
between 'x00' and 'xff'.
This Traversal walks the ByteString in a tree-like fashion enable zippers to seek to locations in logarithmic time and accelerating many monoidal queries, but up to associativity (and constant factors) it is equivalent to the much slower:
chars = unpackedChars % traversed
anyOf chars (== 'h') $ Char8.pack "hello"True