{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
module Data.ByteString.Lazy.Base16.Lens
(
_Hex
, _Base16
, pattern Hex
, pattern Base16
) where
import Control.Lens
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy.Base16 as B16L
_Base16 :: Prism' ByteString ByteString
_Base16 :: p ByteString (f ByteString) -> p ByteString (f ByteString)
_Base16 = (ByteString -> ByteString)
-> (ByteString -> Maybe ByteString)
-> Prism ByteString ByteString ByteString ByteString
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ByteString -> ByteString
B16L.encodeBase16' ((ByteString -> Maybe ByteString)
-> p ByteString (f ByteString) -> p ByteString (f ByteString))
-> (ByteString -> Maybe ByteString)
-> p ByteString (f ByteString)
-> p ByteString (f ByteString)
forall a b. (a -> b) -> a -> b
$ \s :: ByteString
s -> case ByteString -> Either Text ByteString
B16L.decodeBase16 ByteString
s of
Left _ -> Maybe ByteString
forall a. Maybe a
Nothing
Right a :: ByteString
a -> ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
a
{-# INLINE _Base16 #-}
_Hex :: Prism' ByteString ByteString
_Hex :: p ByteString (f ByteString) -> p ByteString (f ByteString)
_Hex = (ByteString -> ByteString)
-> (ByteString -> Maybe ByteString)
-> Prism ByteString ByteString ByteString ByteString
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ByteString -> ByteString
B16L.encodeBase16' ((ByteString -> Maybe ByteString)
-> p ByteString (f ByteString) -> p ByteString (f ByteString))
-> (ByteString -> Maybe ByteString)
-> p ByteString (f ByteString)
-> p ByteString (f ByteString)
forall a b. (a -> b) -> a -> b
$ \s :: ByteString
s -> case ByteString -> Either Text ByteString
B16L.decodeBase16 ByteString
s of
Left _ -> Maybe ByteString
forall a. Maybe a
Nothing
Right a :: ByteString
a -> ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
a
{-# INLINE _Hex #-}
pattern Hex :: ByteString -> ByteString
pattern $bHex :: ByteString -> ByteString
$mHex :: forall r. ByteString -> (ByteString -> r) -> (Void# -> r) -> r
Hex a <- (preview _Hex -> Just a) where
Hex a :: ByteString
a = Tagged ByteString (Identity ByteString)
-> Tagged ByteString (Identity ByteString)
Prism ByteString ByteString ByteString ByteString
_Hex (Tagged ByteString (Identity ByteString)
-> Tagged ByteString (Identity ByteString))
-> ByteString -> ByteString
forall t b. AReview t b -> b -> t
# ByteString
a
pattern Base16 :: ByteString -> ByteString
pattern $bBase16 :: ByteString -> ByteString
$mBase16 :: forall r. ByteString -> (ByteString -> r) -> (Void# -> r) -> r
Base16 a <- (preview _Base16 -> Just a) where
Base16 a :: ByteString
a = Tagged ByteString (Identity ByteString)
-> Tagged ByteString (Identity ByteString)
Prism ByteString ByteString ByteString ByteString
_Base16 (Tagged ByteString (Identity ByteString)
-> Tagged ByteString (Identity ByteString))
-> ByteString -> ByteString
forall t b. AReview t b -> b -> t
# ByteString
a