lens-4.17.1: Lenses, Folds and Traversals

Copyright | (C) 2012-16 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | experimental
Portability | non-portable
Safe Haskell | Safe
Language | Haskell2010

Data.ByteString.Lens

Description

Synopsis

- class IsByteString t where
  - packedBytes :: Iso' [Word8] t
  - packedChars :: Iso' String t
  - bytes :: IndexedTraversal' Int t Word8
  - chars :: IndexedTraversal' Int t Char
- unpackedBytes :: IsByteString t => Iso' t [Word8]
- unpackedChars :: IsByteString t => Iso' t String
- pattern Bytes :: forall s. IsByteString s => [Word8] -> s
- pattern Chars :: forall s. IsByteString s => [Char] -> s

# Documentation

class IsByteString t where Source #

Traversals for ByteStrings.

Minimal complete definition

packedBytes, packedChars

Methods

packedBytes :: Iso' [Word8] t Source #

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

    pack x ≡ x ^. packedBytes
    unpack x ≡ x ^. from packedBytes
    packedBytes ≡ from unpackedBytes

packedChars :: Iso' String t Source #

`pack` (or `unpack`) a list of characters into a strict or lazy `ByteString`.

When writing back to the `ByteString` it is assumed that every `Char` lies between `'\x00'` and `'\xff'`.

    pack x ≡ x ^. packedChars
    unpack x ≡ x ^. from packedChars
    packedChars ≡ from unpackedChars

bytes :: IndexedTraversal' Int t Word8 Source #

Traverse each `Word8` in a strict or lazy `ByteString`

This `ReifiedTraversal` 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:

    bytes ≡ unpackedBytes . traversed

    anyOf bytes (== 0x80) :: ByteString -> Bool

chars :: IndexedTraversal' Int t Char Source #

Traverse the individual bytes in a strict or lazy `ByteString` as characters.

When writing back to the `ByteString` it is assumed that every `Char` lies between `'\x00'` and `'\xff'`.

This `ReifiedTraversal` 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:

    chars ≡ unpackedChars . traversed

    anyOf chars (== 'c') :: ByteString -> Bool

Instances

IsByteString ByteString Source # |
Instance details Defined in Data.ByteString.Lens Methods packedBytes :: Iso' [Word8] ByteString Source # packedChars :: Iso' String ByteString Source # bytes :: IndexedTraversal' Int ByteString Word8 Source # chars :: IndexedTraversal' Int ByteString Char Source #
IsByteString ByteString Source # |
Instance details Defined in Data.ByteString.Lens Methods packedBytes :: Iso' [Word8] ByteString Source # packedChars :: Iso' String ByteString Source # bytes :: IndexedTraversal' Int ByteString Word8 Source # chars :: IndexedTraversal' Int ByteString Char Source #

unpackedBytes :: IsByteString t => Iso' t [Word8] Source #

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

    unpackedBytes ≡ from packedBytes
    unpack x ≡ x ^. unpackedBytes
    pack x ≡  x ^. from unpackedBytes

    unpackedBytes :: Iso' ByteString [Word8]
    unpackedBytes :: Iso' ByteString [Word8]

unpackedChars :: IsByteString t => Iso' t String Source #

`unpack` (or `pack`) a list of characters into a strict (or lazy) `ByteString`

When writing back to the `ByteString` it is assumed that every `Char` lies between `'\x00'` and `'\xff'`.

    unpackedChars ≡ from packedChars
    unpack x ≡ x ^. unpackedChars
    pack x ≡ x ^. from unpackedChars

    unpackedChars :: Iso' ByteString String
    unpackedChars :: Iso' ByteString String

pattern Bytes :: forall s. IsByteString s => [Word8] -> s Source #

pattern Chars :: forall s. IsByteString s => [Char] -> s Source #