lens-3.9.2: Lenses, Folds and Traversals

Portabilitynon-portable
Stabilityexperimental
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellNone

Data.ByteString.Lazy.Lens

Description

Lazy ByteString lenses.

Synopsis

Documentation

packedBytes :: Iso' [Word8] ByteStringSource

pack (or unpack) a list of bytes into a ByteString.

 packedBytesfrom unpackedBytes
 pack x ≡  x ^. packedBytes
 unpack x ≡ x ^. from packedBytes
>>> [104,101,108,108,111]^.packedBytes == Char8.pack "hello"
True

unpackedBytes :: Iso' ByteString [Word8]Source

unpack (or pack) a ByteString into a list of bytes

 unpackedBytesfrom packedBytes
 unpack x ≡ x ^. unpackedBytes
 pack x ≡  x ^. from unpackedBytes
>>> "hello"^.packedChars.unpackedBytes
[104,101,108,108,111]

bytes :: IndexedTraversal' Int64 ByteString Word8Source

Traverse the individual bytes in a ByteString.

This Traversal walks each strict ByteString chunk in a tree-like fashion enable zippers to seek to locations more quickly and accelerate many monoidal queries, but up to associativity (and constant factors) it is equivalent to the much slower:

 bytesunpackedBytes . traversed
>>> anyOf bytes (== 0x80) (Char8.pack "hello")
False

packedChars :: Iso' String ByteStringSource

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'.

 packedCharsfrom unpackedChars
 pack x ≡ x ^. packedChars
 unpack x ≡ x ^. from packedChars
>>> "hello"^.packedChars.each.re (base 16 . enum).to (\x -> if Prelude.length x == 1 then '0':x else x)
"68656c6c6f"

unpackedChars :: Iso' ByteString StringSource

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'.

 unpackedCharsfrom packedChars
 unpack x ≡ x ^. unpackedChars
 pack x ≡ x ^. from unpackedChars
>>> [104,101,108,108,111]^.packedBytes.unpackedChars
"hello"

chars :: IndexedTraversal' Int64 ByteString CharSource

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 each strict ByteString chunk in a tree-like fashion enable zippers to seek to locations more quickly and accelerate many monoidal queries, but up to associativity (and constant factors) it is equivalent to:

 chars = unpackedChars . traversed
>>> anyOf chars (== 'h') "hello"
True