{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
module Data.Text.Lazy.Encoding.Base16.Lens
(
_Base16
, _Hex
, _Base16Lenient
, pattern Hex
, pattern Base16
, pattern Base16Lenient
) where
import Control.Lens
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy.Encoding.Base16 as B16TL
_Base16 :: Prism' Text Text
_Base16 :: p Text (f Text) -> p Text (f Text)
_Base16 = (Text -> Text) -> (Text -> Maybe Text) -> Prism Text Text Text Text
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' Text -> Text
B16TL.encodeBase16 ((Text -> Maybe Text) -> p Text (f Text) -> p Text (f Text))
-> (Text -> Maybe Text) -> p Text (f Text) -> p Text (f Text)
forall a b. (a -> b) -> a -> b
$ \s :: Text
s -> case Text -> Either Text Text
B16TL.decodeBase16 Text
s of
Left _ -> Maybe Text
forall a. Maybe a
Nothing
Right a :: Text
a -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
a
{-# INLINE _Base16 #-}
_Hex :: Prism' Text Text
_Hex :: p Text (f Text) -> p Text (f Text)
_Hex = (Text -> Text) -> (Text -> Maybe Text) -> Prism Text Text Text Text
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' Text -> Text
B16TL.encodeBase16 ((Text -> Maybe Text) -> p Text (f Text) -> p Text (f Text))
-> (Text -> Maybe Text) -> p Text (f Text) -> p Text (f Text)
forall a b. (a -> b) -> a -> b
$ \s :: Text
s -> case Text -> Either Text Text
B16TL.decodeBase16 Text
s of
Left _ -> Maybe Text
forall a. Maybe a
Nothing
Right a :: Text
a -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
a
{-# INLINE _Hex #-}
_Base16Lenient :: Iso' Text Text
_Base16Lenient :: p Text (f Text) -> p Text (f Text)
_Base16Lenient = (Text -> Text) -> (Text -> Text) -> Iso Text Text Text Text
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Text -> Text
B16TL.decodeBase16Lenient Text -> Text
B16TL.encodeBase16
{-# INLINE _Base16Lenient #-}
pattern Hex :: Text -> Text
pattern $bHex :: Text -> Text
$mHex :: forall r. Text -> (Text -> r) -> (Void# -> r) -> r
Hex a <- (preview _Hex -> Just a) where
Hex a :: Text
a = Tagged Text (Identity Text) -> Tagged Text (Identity Text)
Prism Text Text Text Text
_Hex (Tagged Text (Identity Text) -> Tagged Text (Identity Text))
-> Text -> Text
forall t b. AReview t b -> b -> t
# Text
a
pattern Base16 :: Text -> Text
pattern $bBase16 :: Text -> Text
$mBase16 :: forall r. Text -> (Text -> r) -> (Void# -> r) -> r
Base16 a <- (preview _Base16 -> Just a) where
Base16 a :: Text
a = Tagged Text (Identity Text) -> Tagged Text (Identity Text)
Prism Text Text Text Text
_Base16 (Tagged Text (Identity Text) -> Tagged Text (Identity Text))
-> Text -> Text
forall t b. AReview t b -> b -> t
# Text
a
pattern Base16Lenient :: Text -> Text
pattern $bBase16Lenient :: Text -> Text
$mBase16Lenient :: forall r. Text -> (Text -> r) -> (Void# -> r) -> r
Base16Lenient a <- (view (from _Base16Lenient) -> a) where
Base16Lenient a :: Text
a = Getting Text Text Text -> Text -> Text
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Text Text Text
Prism Text Text Text Text
_Base16 Text
a