{-# LANGUAGE CPP #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
#if MIN_VERSION_lens(5,0,0)
{-# LANGUAGE Safe #-}
#else
{-# LANGUAGE Trustworthy #-}
#endif
module Data.Text.Encoding.Base16.Lens
(
_Hex
, _Base16
, _Base16Lenient
, pattern Hex
, pattern Base16
, pattern Base16Lenient
) where
import Control.Lens
import Data.Text (Text)
import qualified Data.Text.Encoding.Base16 as B16T
_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
B16T.encodeBase16 ((Text -> Maybe Text) -> Prism Text Text Text Text)
-> (Text -> Maybe Text) -> Prism Text Text Text Text
forall a b. (a -> b) -> a -> b
$ \Text
s -> case Text -> Either Text Text
B16T.decodeBase16 Text
s of
Left Text
_ -> Maybe Text
forall a. Maybe a
Nothing
Right 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
B16T.encodeBase16 ((Text -> Maybe Text) -> Prism Text Text Text Text)
-> (Text -> Maybe Text) -> Prism Text Text Text Text
forall a b. (a -> b) -> a -> b
$ \Text
s -> case Text -> Either Text Text
B16T.decodeBase16 Text
s of
Left Text
_ -> Maybe Text
forall a. Maybe a
Nothing
Right 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
B16T.decodeBase16Lenient Text -> Text
B16T.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 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 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 _Base16Lenient -> a) where
Base16Lenient Text
a = Tagged Text (Identity Text) -> Tagged Text (Identity Text)
Iso Text Text Text Text
_Base16Lenient (Tagged Text (Identity Text) -> Tagged Text (Identity Text))
-> Text -> Text
forall t b. AReview t b -> b -> t
# Text
a
{-# COMPLETE Base16Lenient #-}