{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE PatternSynonyms #-}
module Data.Text.Optics
( IsText(..)
, unpacked
, _Text
, pattern Text
) where
import qualified Data.Text as Strict
import qualified Data.Text.Lazy as Lazy
import qualified Data.Text.Lazy.Builder as B
import Optics.Core
import qualified Data.Text.Lazy.Optics as Lazy
import qualified Data.Text.Strict.Optics as Strict
class IsText t where
packed :: Iso' String t
builder :: Iso' t B.Builder
text :: IxTraversal' Int t Char
text = Iso' t String
forall t. IsText t => Iso' t String
unpacked Iso' t String
-> Optic A_Traversal (WithIx Int) String String Char Char
-> IxTraversal' Int t Char
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic A_Traversal (WithIx Int) String String Char Char
forall i (f :: * -> *) a b.
TraversableWithIndex i f =>
IxTraversal i (f a) (f b) a b
itraversed
{-# INLINE text #-}
instance IsText String where
packed :: Iso' String String
packed = (String -> String) -> (String -> String) -> Iso' String String
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso String -> String
forall a. a -> a
id String -> String
forall a. a -> a
id
text :: Optic A_Traversal (WithIx Int) String String Char Char
text = Optic A_Traversal (WithIx Int) String String Char Char
forall i (f :: * -> *) a b.
TraversableWithIndex i f =>
IxTraversal i (f a) (f b) a b
itraversed
builder :: Iso' String Builder
builder = Iso' String Text
Lazy.packed Iso' String Text
-> Optic An_Iso NoIx Text Text Builder Builder
-> Iso' String Builder
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic An_Iso NoIx Text Text Builder Builder
forall t. IsText t => Iso' t Builder
builder
{-# INLINE packed #-}
{-# INLINE text #-}
{-# INLINE builder #-}
unpacked :: IsText t => Iso' t String
unpacked :: Iso' t String
unpacked = Optic An_Iso NoIx String String t t
-> Optic (ReversedOptic An_Iso) NoIx t t String String
forall k (is :: IxList) s t a b.
(ReversibleOptic k, AcceptsEmptyIndices "re" is) =>
Optic k is s t a b -> Optic (ReversedOptic k) is b a t s
re Optic An_Iso NoIx String String t t
forall t. IsText t => Iso' String t
packed
{-# INLINE unpacked #-}
_Text :: IsText t => Iso' t String
_Text :: Iso' t String
_Text = Optic An_Iso NoIx String String t t
-> Optic (ReversedOptic An_Iso) NoIx t t String String
forall k (is :: IxList) s t a b.
(ReversibleOptic k, AcceptsEmptyIndices "re" is) =>
Optic k is s t a b -> Optic (ReversedOptic k) is b a t s
re Optic An_Iso NoIx String String t t
forall t. IsText t => Iso' String t
packed
{-# INLINE _Text #-}
pattern Text :: IsText t => String -> t
pattern $bText :: String -> t
$mText :: forall r t. IsText t => t -> (String -> r) -> (Void# -> r) -> r
Text a <- (view _Text -> a) where
Text String
a = Optic' An_Iso NoIx t String -> String -> t
forall k (is :: IxList) t b.
Is k A_Review =>
Optic' k is t b -> b -> t
review Optic' An_Iso NoIx t String
forall t. IsText t => Iso' t String
_Text String
a
instance IsText Strict.Text where
packed :: Iso' String Text
packed = Iso' String Text
Strict.packed
builder :: Iso' Text Builder
builder = Iso' Text Builder
Strict.builder
text :: IxTraversal' Int Text Char
text = IxTraversal' Int Text Char
Strict.text
{-# INLINE packed #-}
{-# INLINE builder #-}
{-# INLINE text #-}
instance IsText Lazy.Text where
packed :: Iso' String Text
packed = Iso' String Text
Lazy.packed
builder :: Optic An_Iso NoIx Text Text Builder Builder
builder = Optic An_Iso NoIx Text Text Builder Builder
Lazy.builder
text :: IxTraversal' Int Text Char
text = IxTraversal' Int Text Char
Lazy.text
{-# INLINE packed #-}
{-# INLINE builder #-}
{-# INLINE text #-}