optics-extra-0.4.2.1: Extra utilities and instances for optics-core
Safe HaskellNone
LanguageHaskell2010

Data.Text.Optics

Description

This module provides Isos for converting strict or lazy Text to or from a String or Builder, and an IxTraversal for traversing the individual characters of a Text.

The same combinators support both strict and lazy text using the IsText typeclass. You can import Data.Text.Strict.Optics or Data.Text.Lazy.Optics instead if you prefer monomorphic versions.

Synopsis

Documentation

class IsText t where Source #

Traversals for strict or lazy Text

Minimal complete definition

packed, builder

Methods

packed :: Iso' String t Source #

This isomorphism can be used to pack (or unpack) strict or lazy Text.

pack x ≡ x ^. packed
unpack x ≡ x ^. re packed
packedre unpacked

builder :: Iso' t Builder Source #

Convert between strict or lazy Text and a Builder.

fromText x ≡ x ^. builder

text :: IxTraversal' Int t Char Source #

Traverse the individual characters in strict or lazy Text.

text = unpacked . traversed

unpacked :: IsText t => Iso' t String Source #

This isomorphism can be used to unpack (or pack) both strict or lazy Text.

unpack x ≡ x ^. unpacked
pack x ≡ x ^. re unpacked

This Iso is provided for notational convenience rather than out of great need, since

unpackedre packed

_Text :: IsText t => Iso' t String Source #

This is an alias for unpacked that makes it clearer how to use it with (#).

_Text = re packed
>>> _Text # "hello" :: Strict.Text
"hello"

pattern Text :: IsText t => String -> t Source #