{-# LANGUAGE NoImplicitPrelude #-}
module Control.Lens.Cons.Extras
(
recons
, unfoldr
) where
import Data.Function (id)
import Data.Maybe (Maybe)
import Data.String (String)
import Data.Word (Word8)
import Control.Lens
import Control.Lens ((#))
import Control.Lens.Cons (Cons, cons, uncons)
import Control.Lens.Empty (AsEmpty(..))
import Control.Lens.Fold (foldrOf, unfolded)
import Control.Lens.Iso (lazy, strict)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
import Data.ByteString.Lens (packedBytes, unpackedBytes)
import qualified Data.Text as T
import Data.Text.Lens (packed, unpacked)
import qualified Data.Text.Lazy as TL
{-# NOINLINE recons #-}
recons :: (Cons s1 s1 a a, Cons s2 s2 a a, AsEmpty s2) => Getter s1 s2
recons :: forall s1 a s2.
(Cons s1 s1 a a, Cons s2 s2 a a, AsEmpty s2) =>
Getter s1 s2
recons = (s1 -> s2) -> (s2 -> f s2) -> s1 -> f s1
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to ((s1 -> Maybe (a, s1)) -> s1 -> s2
forall s2 a s1.
(Cons s2 s2 a a, AsEmpty s2) =>
(s1 -> Maybe (a, s1)) -> s1 -> s2
unfoldr s1 -> Maybe (a, s1)
forall s a. Cons s s a a => s -> Maybe (a, s)
uncons)
unfoldr :: (Cons s2 s2 a a, AsEmpty s2) => (s1 -> Maybe (a, s1)) -> s1 -> s2
unfoldr :: forall s2 a s1.
(Cons s2 s2 a a, AsEmpty s2) =>
(s1 -> Maybe (a, s1)) -> s1 -> s2
unfoldr s1 -> Maybe (a, s1)
f = Getting (Endo s2) s1 a -> (a -> s2 -> s2) -> s2 -> s1 -> s2
forall r s a. Getting (Endo r) s a -> (a -> r -> r) -> r -> s -> r
foldrOf ((s1 -> Maybe (a, s1)) -> Fold s1 a
forall b a. (b -> Maybe (a, b)) -> Fold b a
unfolded s1 -> Maybe (a, s1)
f) a -> s2 -> s2
forall s a. Cons s s a a => a -> s -> s
cons (Tagged () (Identity ()) -> Tagged s2 (Identity s2)
forall a. AsEmpty a => Prism' a ()
Prism' s2 ()
_Empty (Tagged () (Identity ()) -> Tagged s2 (Identity s2)) -> () -> s2
forall t b. AReview t b -> b -> t
# ())
{-# RULES
"recons/id"
recons = id
"recons/string-text"
recons = packed :: Getter String T.Text
"recons/text-string"
recons = unpacked :: Getter T.Text String
"recons/string-lazytext"
recons = packed :: Getter String TL.Text
"recons/lazytext-string"
recons = unpacked :: Getter TL.Text String
"recons/text-strict"
recons = strict :: Getter TL.Text T.Text
"recons/text-lazy"
recons = lazy :: Getter T.Text TL.Text
"recons/list-bs"
recons = packedBytes :: Getter [Word8] B.ByteString
"recons/bs-list"
recons = unpackedBytes :: Getter B.ByteString [Word8]
"recons/list-lazybs"
recons = packedBytes :: Getter [Word8] L.ByteString
"recons/lazybs-list"
recons = unpackedBytes :: Getter L.ByteString [Word8]
"recons/bs-strict"
recons = strict :: Getter L.ByteString B.ByteString
"recons/bs-lazy"
recons = lazy :: Getter B.ByteString L.ByteString
#-}